gpt4 book ai didi

python - DataFrame 使用索引获取行

转载 作者:行者123 更新时间:2023-11-28 22:20:37 25 4
gpt4 key购买 nike

我正在尝试找到一种使用索引获取数据帧行的方法,其结果与使用 data_file.iterrows() 的结果相同。我尝试了以下代码,但它们并不相同。有什么办法吗?谢谢!

for row in data_file.iterrows():
print(row == data_file.iloc[0])
print(row)
print(data_file.iloc[0])
break

最佳答案

对应的系列值在 index1 上,有帮助吗?

文档: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.iterrows.html

DataFrame.iterrows()[source]

Iterate over DataFrame rows as (index,Series) pairs.

print(row[1] == data_file.iloc[0])

另一种解决方案:

for ind, row in data_file.iterrows():

关于python - DataFrame 使用索引获取行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48835864/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com