[Solved] How can I combine row values into a new row in pandas [closed]


Use:

df.set_index('Cities',inplace=True)
df.loc['A']=df.loc['A']+df.loc['B']
df=df.drop('B').rename(index={'A':'A/B'}).reset_index()

set_index('Cities') sets Cities as an index to add using loc. Then A is renamed A / B and cities are reset as a column using reset_index

note: if Cities was the index you don need:

df.set_index('Cities',inplace=True)

2

solved How can I combine row values into a new row in pandas [closed]