Issue
I have dataset of 5 columns, I'll call them ['A', 'B', 'C', 'D', 'F') for here.
I am trying to concatenate A, B and C and still have D and F in the dataframe.
Maybe concatenating isn't even the thing I am looking for? I just want the strings from A, B and C to be in one columns.
I tried to use newdf['ABC'] = newdf['A'] + newdf['B'] + newdf['C']
I thought it would combine the columns into a new column called 'ABC' and leave D and F alone but it overwrites the dataframe to have only one column (ABC)
I'm just startinag of so that might be a basic question but I just didn't find a helping answer.
Thank you in advance!
Solution
>>> df
A B C D E
0 1 2 3 4 5
>>> df['ABC'] = df['A'] + df['B'] + df['C']
>>> df
A B C D E ABC
0 1 2 3 4 5 6
It does not overwrite D, E columns.
If it's not the one you want, can you explain your code and input/output?
Answered By - jaemmin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.