df = pd.read_csv('D:\\project_codes\\USA_Presidential_Contributor\\2012-P00000001-ALL.csv',index_col=False)

看看官方解释

index_col : int or sequence or False, default None Column to use as the row labels of the DataFrame. If a sequence is given, a MultiIndex is used. If you have a malformed file with delimiters at the end of each line, you might consider index_col=False to force pandas to not use the first column as the index (row names)



index_col默认不使用数据表的列作为行标签,不过如果列名数小于数据的列数,可以指定某些列为行标签。如下面的数据,列名数比数据列数少3个,可以指定3列为行标签(索引)。index_col=False to force pandas to _not_use the first column as the index (row names)

 

 

data = pd.read_csv("./data/stock_day2.csv",index_col=[4,6,7])
data.head()

 

posted on 2021-12-23 20:16  风生水起  阅读(785)  评论(0编辑  收藏  举报