Python 熊猫数据帧定位码
我有一个pandasPython 熊猫数据帧定位码,python,python-3.x,pandas,Python,Python 3.x,Pandas,我有一个pandasDataFrame,我正在寻找其中的最小值 print(df.loc[df['Price'].idxmin()]) 它正在工作,我可以打印整个“行”,结果如下: Country Switzerland City Zurich Airport Zurich Carrier Vueling Airlines Type
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]
从技术上讲,链接索引,
print(df.loc[df['Price'].idxmin(),'Airport'])
比IMO+1更好,不过你太棒了!:)谢谢大家!@EdChum faire足以得到R/W情况下更明确的变化。编辑,谢谢!