没有将第一行数据读入数据帧

时间:2017-08-06 19:45:19

标签: python pandas

我正在阅读csv,看起来像:

date        total_pnl_per_pos
10/01/2006             -0.027
11/01/2006         0.34400804
12/01/2006        0.894075999
13/01/2006       -0.221139488

但是,当我使用以下代码将.csv读入数据框(df)时:

    for dirName,sundirList, fileList in os.walk(rootdir):
             print('Found directory: %s' % dirName)
             for fname in fileList:
                 print('\t%s' % fname)
                 full_path = os.path.join(dirName, fname)
                 df = pd.read_csv(full_path, header=1, usecols=[0,15],parse_dates=[0], dayfirst=True,index_col=[0], names=['date', 'total_pnl_per_pos'])
                 print(df)

我收到以下内容:

            total_pnl_per_pos
date                         
11/01/2006           0.344008
12/01/2006           0.894076
13/01/2006          -0.221139

缺少第一行数据。我试过修改pd.read行,但是我无法检索10/01/2006的数据。

任何帮助都会有很多学徒。 感谢

1 个答案:

答案 0 :(得分:0)

您需要参数Problem reading from input stream, java.io.EOFException: \n not found: size=14639 content=7b2261727469636c6573223a7b22726573756c7473223a5b7b226964223a2231... java.io.IOException: unexpected end of stream on Connection{eventregistry.org:80, proxy=DIRECT@ hostAddress=185.49.3.27 cipherSuite=none protocol=http/1.1} (recycle count=0) at com.android.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:210) at com.android.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:80) at com.android.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:905) at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:789) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:443) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:388) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:501) 作为列名称读取第一行文件。

如果与列名相同,则删除参数header=0,然后还必须删除names