熊猫数据帧位置



我有一个熊猫DataFrame,我正在寻找其中的最小值。

print(df.loc[df['Price'].idxmin()])

它正在工作,我可以打印整行,这是结果:

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

例如,如何仅打印AirportId列?

谢谢!

通过过滤它:

print(df.loc[df['Price'].idxmin()]['Airport'])

如果要将数据写入该单元格,请继续使用 loc

df.loc[df['Price'].idxmin(),'Airport']

假设这是您的数据框:

your_df = pd.DataFrame(data={'Airport':['x','y','z'], 'type': ['A','B','C'],
      'price':[5450, 5450, 15998]})

您可以像这样访问第一列:

print your_df.loc[your_df['price'].idxmin()].values[0]

最新更新