[英]Iterating through two pandas dataframes and appending data from one dataframe to the other
I have two pandas data-frames that look like this: 我有两个看起来像这样的熊猫数据框:
data_frame_1: data_frame_1:
index un_id city
1 abc new york
2 def atlanta
3 gei toronto
4 lmn tampa
data_frame_2: data_frame_2:
index name un_id
1 frank gei
2 john lmn
3 lisa abc
4 jessica def
I need to match names to cities via the un_id column either in a new data-frame or an existing data-frame. 我需要通过新数据框架或现有数据框架中的un_id列将名称与城市匹配。 I am having trouble figuring out how to iterate through one column, grab the un_id, iterate through the other un_id column in the other data-frame with that un_id, and then append the information needed back to the original data-frame.
我在弄清楚如何迭代一列,获取un_id,使用该un_id遍历另一个数据帧中的另一个un_id列时遇到麻烦,然后将所需的信息附加回原始数据帧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.