python pandas.read_csv()读取csv文件,第一列数据作为index(索引)的解决办法

示例:

df = pd.read_csv(fpath)

直接读取会使文件中第一列数据默认为df的index,使列名和列数据发生错位。可以添加以下参数:

index_col : int or sequence or False, default None

修改为如下代码即可使index设为默认从0开始:

df = pd.read_csv(fpath, index_col=False )

官方文档:http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html?highlight=read_csv#pandas.read_csv

猜你喜欢

转载自blog.csdn.net/qq_32650831/article/details/121000332