You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to merge multiple dataframe with consecutive merge operations, I want to add a suffix to the name of the newly merged column names. A simplified version of my code looks like this:
In [45]: pd.concat([f0,f1,f2],axis=1,ignore_index=True)
Out[45]:
0 1 2
a 1 6 7
b 2 5 9
c 3 4 8
suffixes only apply if there are duplicate columns which after the first merge there are not (when compared to the 3rd)
In [46]: merged1 = merged.merge(f1, left_index=True, right_index=True, suffixes=("_0", "_1"))
In [47]: merged1
Out[47]:
data_0 data_1
c 3 4
b 2 5
a 1 6
In [48]: merged1.merge(f2, left_index=True, right_index=True, suffixes=("", "_2"))
Out[48]:
data_0 data_1 data
a 1 6 7
c 3 4 8
b 2 5 9
Ah thanks for the explanation, I missed the fact that suffixes only get applied to duplicate column names. And indeed the concat solution is simpler. And for the record: concat(... ignore_index=True) is exactly the opposite of what I want, but with concat(... ignore_index=False) it works nicely.
I am trying to merge multiple dataframe with consecutive merge operations, I want to add a suffix to the name of the newly merged column names. A simplified version of my code looks like this:
With pandas 0.15.2 on python 2.7 this returns:
while I would have expected
The text was updated successfully, but these errors were encountered: