Outer merging two data frames in place in pandas

会有一股神秘感。 提交于 2019-12-04 00:58:05

问题


How can I outer merge two data frames in place in 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.


回答1:


Since there is not inplace parameter in pandas.merge i think the most you can do is:

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.



来源:https://stackoverflow.com/questions/44937462/outer-merging-two-data-frames-in-place-in-pandas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!