CD_FARE MTH DAY ID_CALENDAR H0 H1 H2 H3 PE1 PE2 PE3 PE4
2.0 1 M Cal01 1 2 1 3 0.14 0.15 0.1 0.2
2.0 1 T Cal01 1 2 1 3 0.14 0.16 0.1 0.2
2.0 1 W Cal01 1 2 4 3 0.14 0.12 0.1 0.2
2.0 1 T Cal01 2 2 1 3 0.14 0.11* 0.1 0.2
2.0 1 F Cal01 4 2 1 3 0.14 0.18 0.1 0.2
我想知道如何从特定单元格获取值。
例如:我想返回值0.11。 我知道行的位置(在本例中为 3)和列的名称(PE2)。 我可以这样选择数据吗?:
data = df.iloc[3, 'PE2']
最佳答案
显然它不起作用,它给出了一个 ValueError
ValueError: Location based indexing can only have [integer, integer slice (START point is INCLUDED, END point is EXCLUDED), listlike of integers, boolean array] types
但是如果您使用 df.loc[3, 'PE2']
而不是 iloc
方法,它就可以工作
关于python - 按行和列获取单元格的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40173445/