Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.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
Python expndtw-1:在excel中提取具有数字列名的数据_Python_Pandas_Numpy - Fatal编程技术网

Python expndtw-1:在excel中提取具有数字列名的数据

Python expndtw-1:在excel中提取具有数字列名的数据,python,pandas,numpy,Python,Pandas,Numpy,我需要每年使用pandas从excel文件中提取数据,excel文件的格式如下: File-a 2000 2001 2002 01/01 0.50 6.7 4.66 01/02 1.55 5.5 5.8 01/03 2.36 4.4 7.8 我正在做这样的事情: xl = pd.ExcelFile('file_path') sheets= xl.sheet_names table2 =

我需要每年使用pandas从excel文件中提取数据,excel文件的格式如下:

File-a          
         2000     2001   2002
01/01    0.50     6.7    4.66
01/02    1.55     5.5    5.8
01/03    2.36     4.4    7.8
我正在做这样的事情:

xl = pd.ExcelFile('file_path')
sheets= xl.sheet_names
table2 = xl.parse(sheets[0], header=0)

df_append=table2.ix[1:,1:2]

arr=df_append.values.tolist()
arr=np.squeeze(np.asarray(arr))
price_arr=np.array2string(arr,separator=', ')
print price_arr
我需要在数组中转换2000、2001等列中的数据,并使用列名动态提取这些数据,而不是像上面所做的列索引那样。我尝试过这样做,但没有成功:

 df_append=table2.ix[1:,'2000']

您能建议我如何根据特定的年份列提取数据吗?此外,年份列从第二行开始,不在标题列中。谢谢。

您期望的最终输出是什么?[0.5,1.55,2.36]如果我为2000年提取。请发布
table2.head().reset_index().to_dict('list')
,这样我们就可以确切地了解您正在使用的数据帧。这只是我创建的原始表的虚拟表,但原始表是这样的:{u'File-a':[nan,u'1/1 00:00-01:00',u'1/1 01:00-02:00',u'1/1 02:00-03:00',u'1/1 03:00-04:00'],“index':[0L,1L,2L,3L,4L],2015:[nan,0.5,1.55,2.36,0.64]]