I have a dataframe that looks something like this:
Row-Labels 300 301
0 BLR 1
1 BLR 2 2
2 NSL
3 RFR 3
4 TNC 22
What I want to get is something like this:
Row-Labels 300 301
0 BLR 3 2
1 NSL
2 RFR 3
3 TNC 22
That is, I want to merge all rows into one where row-labels column values are same. This merge should be such that the column in the resulting row should sum all values in column A for row-labels value 'BLR' and put other values as it is in the that column of the row if no sum is required.
What I have done so far is something like this:
for i in range(300, 301):
temp_final_df.append(final_df.groupby(['Row-Labels'])['{}'.format(i)].apply(sum).reset_index())
But its output is not correct. In short, I want to merge rows such that Row_labels column values become unique. Any other ideas as how can I achieve this?