Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.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数据帧中的所有元素_Python_Pandas - Fatal编程技术网

读取Python数据帧中的所有元素

读取Python数据帧中的所有元素,python,pandas,Python,Pandas,我有一个数据集,其中的列表示年份,可以随时间动态变化。 数据集看起来像- Unnamed: 0 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 0 North America 109.24 119.60946 144.29389 187.86691 227.29032 265.21215 340.15054 472.83005 666.

我有一个数据集,其中的列表示年份,可以随时间动态变化。 数据集看起来像-

Unnamed: 0  2000    2001    2002    2003    2004    2005    2006    2007    2008    2009    2010
0   North America   109.24  119.60946   144.29389   187.86691   227.29032   265.21215   340.15054   472.83005   666.47907   768.71809   914.4242
1   Bermuda 0   0   0   0   0   0   0   0   0   0   0
2   Canada  3.7 3.9 4   4   4   4.6 5.2 15.4    16.7    22.1    26.4
3   Greenland   0   0   0   0   0   0   0   0   0   0   0
4   Mexico  0   0   0   0   0   0   0   0.1 0.1 0.103   0.4

我想迭代所有元素,查看是否有单元格大于50,并打印相应的国家/地区名称。

首先按第一列按或
索引列创建索引
参数:


说明

通过(
)比较所有数据:

并通过以下方式检查每行是否至少有一个值为
True

使用
df.index
进行最后一次筛选:

print (df.index[df.gt(50).any(axis=1)])

Index(['North America'], dtype='object', name='Unnamed: 0')

如果我的答案有帮助,别忘了——点击答案旁边的复选标记,将其从灰色变为填充。谢谢
out = df.index[df.gt(50).any(axis=1)].tolist()
print (out)
['North America']
print (df.gt(50))
                2000   2001   2002   2003   2004   2005   2006   2007   2008  \
Unnamed: 0                                                                     
North America   True   True   True   True   True   True   True   True   True   
Bermuda        False  False  False  False  False  False  False  False  False   
Canada         False  False  False  False  False  False  False  False  False   
Greenland      False  False  False  False  False  False  False  False  False   
Mexico         False  False  False  False  False  False  False  False  False   

                2009   2010  
Unnamed: 0                   
North America   True   True  
Bermuda        False  False  
Canada         False  False  
Greenland      False  False  
Mexico         False  False 
print (df.gt(50).any(axis=1))
Unnamed: 0
North America     True
Bermuda          False
Canada           False
Greenland        False
Mexico           False
dtype: bool
print (df.index[df.gt(50).any(axis=1)])

Index(['North America'], dtype='object', name='Unnamed: 0')