简体   繁体   English

如何循环到 dataframe pandas 中的列

[英]How to loops to column in dataframe pandas

i am the newbie with pandas, can i loops 2 column by position 1 and 3 in pandas dataframe below我是 pandas 的新手,我可以通过 position 1 和 3 在 pandas Z6A55064B5CDF475C 下方循环 2 列吗

import pandas as pd
inp = [(9,8,7),(4,6,8),(8,4,7),(1,12,7)]

df = pd.DataFrame(data=inp,columns=["a","b","d"])
print(df)

the result will bee like this结果会像这样

tokyo
7
new york
8
london
7

Thanks you for your help!谢谢你的帮助!

Here is a solution from a previous post where they use a nested loop to loop through column names.这是上一篇文章中的一个解决方案,他们使用嵌套循环遍历列名。 You can also use the index to find specific locations in a pandas dataframe.您还可以使用索引在 pandas dataframe 中查找特定位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM