问题
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