Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.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,我有一个如下所示的数据框 customers ... Date 2006-01-03 98 ... 2006-01-04 120 ... 2006-01-05 103 ... 2006-01-06 95 ... 2006-01-09

我有一个如下所示的数据框

             customers       ...
Date                                             
2006-01-03          98       ...
2006-01-04         120       ...   
2006-01-05         103       ...  
2006-01-06          95       ... 
2006-01-09         103       ...
我想得到客户数超过100的行并打印出来

for x in range(len(df)):
    if df['customers'].iloc[x] > 100:
        print(df['customers'].iloc[x]) 
但我不知道如何打印出符合条件的行的日期(索引)。我的目标是这样打印:

2006-01-04
120
2006-01-05
103
2006-01-09
103
考虑使用:

要获得指定的确切输出格式,请迭代
query()
结果:

for date, customer in df.query('customers > 100').values:
    print(date)
    print(customer)

2006-01-04
120
2006-01-05
103
2006-01-09
103

df[df['customer']>100]将完成此工作。。。
虽然您可以使用循环在stackoverflow上找到许多类似的答案,但您可以使用df.index[x]在输出中获取数据

for x in range(len(df)):
    if df['customers'].iloc[x] > 100:
        print(df.index[x])
        print(df['customers'].iloc[x])

2006-01-04
120
2006-01-05
103
2006-01-09
103

Date列是此数据帧的索引。您是否碰巧知道如何获得符合条件的每一行客户价值的日期?我不确定我是否理解您的要求。如果
Date
是索引,则
query()
函数的工作方式相同。如果您只希望日期与您的条件相匹配(而不是OP desired output所显示的日期),那么只需提取
索引
df.query('customers>100')。index.value
for x in range(len(df)):
    if df['customers'].iloc[x] > 100:
        print(df.index[x])
        print(df['customers'].iloc[x])

2006-01-04
120
2006-01-05
103
2006-01-09
103