[英]Pandas dataframe loc
I have a pandas DataFrame
and I'm looking for the min value in it. 我有一个熊猫
DataFrame
,我正在寻找其中的最小值。
print(df.loc[df['Price'].idxmin()])
It's working and i can print the whole 'line', This is the result: 它正在工作,我可以打印整个“行”,这是结果:
Country Switzerland
City Zurich
Airport Zurich
Carrier Vueling Airlines
Type Direct
Date 2017-09-05T00:00:00
Price 12360
AirportId ZRH
Name: 97, dtype: object
Process finished with exit code 0
How can I print for example only the AirportId
column? 例如,如何仅打印
AirportId
列?
Thank you! 谢谢!
By filtering against it: 通过过滤:
print(df.loc[df['Price'].idxmin()]['Airport'])
If you intend to write data into that cell, keep using loc
: 如果您打算将数据写入该单元格,请继续使用
loc
:
df.loc[df['Price'].idxmin(),'Airport']
let's say this is your data frame: 假设这是您的数据框:
your_df = pd.DataFrame(data={'Airport':['x','y','z'], 'type': ['A','B','C'],
'price':[5450, 5450, 15998]})
you can access th efirst column like this: 您可以像这样访问efirst列:
print your_df.loc[your_df['price'].idxmin()].values[0]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.