pandas 外部合并熊猫中的两个数据框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44937462/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Outer merging two data frames in place in pandas
提问by Franck Dernoncourt
How can I outer merge two data frames in place in pandas?
如何在 Pandas 中外部合并两个数据框?
For example, assume we have these two data frames:
例如,假设我们有这两个数据框:
import pandas as pd
s1 = pd.DataFrame({
'time':[1234567000,1234567005,1234567009],
'X1':[96.32,96.01,96.05]
},columns=['time','X1']) # to keep columns order
s2 = pd.DataFrame({
'time':[1234567001,1234567005],
'X2':[23.88,23.96]
},columns=['time','X2']) # to keep columns order
They could be merged with pandas.DataFrame.merge(s3 = pd.merge(s1,s2,how='outer')
) or with pandas.merge(s3=s1.merge(s2,how='outer')
), but it isn't in place. Instead, I'd like the merged data frame to replace s1 in memory.
它们可以与pandas.DataFrame.merge( s3 = pd.merge(s1,s2,how='outer')
) 或 pandas.merge( s3=s1.merge(s2,how='outer')
)合并,但没有到位。相反,我希望合并的数据框替换内存中的 s1。
采纳答案by Rayhane Mama
Since there is not inplace
parameter in pandas.mergei think the most you can do is:
由于pandas.merge 中没有inplace
参数,我认为您最多可以做的是:
s1 = pd.merge(s1,s2,how='outer')
other than that, i don't think there's much left to do.
Hope that was helpful somehow.
除此之外,我认为没有太多事情要做。
希望以某种方式有所帮助。