[英]Zip pandas dataframes into a new dataframe
I have 2 dataframes: 我有2个数据帧:
df_A DF_A
country_codes
0 4
1 8
2 12
3 16
4 24
and df_B 和df_B
continent_codes
0 4
1 3
2 5
3 6
4 5
Both dataframes have same length, but no common column. 两个数据帧都具有相同的长度,但没有公共列。 I want to concatenate the two but since not all values are common, I get lots of NaNs. 我想连接这两个,但由于不是所有的值都很常见,我得到了很多NaN。 How do I concatenate or zip them up into a combined dataframe? 如何将它们连接或压缩成组合数据帧?
-- EDIT desired output is this: - 编辑所需的输出是这样的:
country_codes continent_codes
0 4 4
1 8 3
2 12 5
3 16 6
4 24 5
From the comments: 来自评论:
I feel like this is too simple, but may I suggest: 我觉得这太简单了,但我可以建议:
df_A['continent_codes'] = df_B['continent_codes']
print(df_A)
Output: 输出:
country_codes continent_codes
0 4 4
1 8 3
2 12 5
3 16 6
4 24 5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.