这是文件内容(名为 sample.txt)
gvkeyx from thru conm gvkey co_conm co_tic
123453 19661214 19890426 S&P 500 Comp-Ltd 010490 TEXAS EASTERN CORP PEL4
123453 19670101 . S&P 500 Comp-Ltd 001078 ABBOTT LABORATORIES ABT
123453 19670101 . S&P 500 Comp-Ltd 001300 HONEYWELL INTERNATIONAL INC HON
123453 19670101 . S&P 500 Comp-Ltd 001356 ALCOA INC AA
123453 19670101 . S&P 500 Comp-Ltd 001408 FORTUNE BRANDS INC FO
我输入阅读它的代码:
In [16]: colspecs = [(0, 9), (10, 21), (22, 33), (34, 53), (54, 63), (64, 92), (93, 99)]
In [17]: df = read_fwf('sample.txt', colspecs = colspecs, header=None, index_col=None)
In [18]: df[:2]
Out[19]:
<class 'pandas.core.frame.DataFrame'>
Int64Index: 2 entries, 0 to 1
Data Columns:
X.1 2 non-null values
X.2 2 non-null values
X.3 2 non-null values
X.4 2 non-null values
X.5 2 non-null values
X.6 2 non-null values
X.7 2 non-null values
dtypes: object(7)
我无法理解这个输出,因为它与文件完全不同。任何意见和建议都会有所帮助。谢谢