How to avoid NaN index values when Importing from .csv w/o headers to a pandas dataframe?

早过忘川 提交于 2020-01-11 13:13:23

问题


I have a .csv file without headers. I want to import it to create a pandas dataframe object.

df1 = pd.read_csv(infile, global_sep, header = 0)

When doing print df1.head(), I yield the following output:

    1491895800000   -64  640  15424
0   1491895799995   -64  640  15424
1   1491895799990   -64  640  15424
2   1491895799985   -64  640  15424
3   1491895799980   -64  640  15424
4   1491895799975   -64  640  15424

Doing df1.reset_index(inplace = True, drop = True), doesn't change the output.

How to avoid NaN index values when Importing from .csv w/o headers to a pandas dataframe?

When doing

print df1.iloc[0]

The output should be

0 1491895800000   -64  640  15424

回答1:


If you use:

df1 = pd.read_csv(infile, global_sep, header=None)

It will work.



来源:https://stackoverflow.com/questions/43657078/how-to-avoid-nan-index-values-when-importing-from-csv-w-o-headers-to-a-pandas-d

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!