从.csv w/o标头导入到 pandas 数据框时,如何避免NaN索引值? [英] How to avoid NaN index values when Importing from .csv w/o headers to a pandas dataframe?
本文介绍了从.csv w/o标头导入到 pandas 数据框时,如何避免NaN索引值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个.csv
文件,没有标题.我想将其导入以创建熊猫数据框对象.
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)
执行print df1.head()
时,输出以下内容:
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
执行df1.reset_index(inplace = True, drop = True),
不会更改输出.
从无标题的.csv导入到熊猫数据框时如何避免NaN索引值?
这样做的时候
print df1.iloc[0]
输出应为
0 1491895800000 -64 640 15424
推荐答案
如果使用:
df1 = pd.read_csv(infile, global_sep, header=None)
它将起作用.
这篇关于从.csv w/o标头导入到 pandas 数据框时,如何避免NaN索引值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文