在DataFrame中选择行与列

问题描述 投票:-2回答:1

在Pandas DataFrame中,比如说汽车,我可以像这样选择并打印一个列:

# country is a column
print(cars['country'])

但是,当我尝试用一​​行做同样的事情时,我失败了:

#US is a row
print(cars['US'])
KeyError: 'US'

然后我尝试了这个并且它有效:

print(cars['US':'US'])

那么,在Pandas DataFrame中,列索引是键而行索引不是?有人可以解释使行选择比列选择更复杂的原因是什么?

python pandas computer-science data-science
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.