Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Pandas PD.Read\u Excel是否将列作为索引读取?_Pandas_Python 2.7_Dataframe - Fatal编程技术网

Pandas PD.Read\u Excel是否将列作为索引读取?

Pandas PD.Read\u Excel是否将列作为索引读取?,pandas,python-2.7,dataframe,Pandas,Python 2.7,Dataframe,我不认为这个问题是重复的,因为您链接的问题引用了如何使用excel列标签作为数据框的列标签。我不是在问,我是在问为什么要将列读入索引? 我使用read_excel pandas方法将excel工作表作为数据框架引入python。但是,当我执行如下代码时: pd.read_excel(df) 它产生以下输出: df.columns Index([u'Column1', u'Column2', u'Column3'], dtype='object') df.columns Index([u'Co

我不认为这个问题是重复的,因为您链接的问题引用了如何使用excel列标签作为数据框的列标签。我不是在问,我是在问为什么要将列读入索引?

我使用read_excel pandas方法将excel工作表作为数据框架引入python。但是,当我执行如下代码时:

pd.read_excel(df)
它产生以下输出:

df.columns
Index([u'Column1', u'Column2', u'Column3'], dtype='object')
df.columns
Index([u'Column2', u'Column3'], dtype='object')
为什么read_excel方法似乎要将我的列作为索引导入?我该如何阻止这种情况发生?我曾尝试使用如下代码:

pd.read_excel(df,index_col=0)
但是,这会产生以下输出:

df.columns
Index([u'Column1', u'Column2', u'Column3'], dtype='object')
df.columns
Index([u'Column2', u'Column3'], dtype='object')

您是否需要
pd.read\u excel(df,header=None)
?您的excel第一行被导入为数据框列索引。那么我是否误解了这一行:“index([u'Column2',u'Column3'],dtype='object')”->我将其理解为“此数据框的索引是Column2,Column3”?