user17710367
user17710367

Reputation:

Splitting Multiple Columns in dataframe

Here is the code I am currently working with.

df['RESULT_DATE'] = df['RESULT'] + " , " + df['DATE'].astype(str)
grouped=df.groupby('PID')['RESULT_DATE'].apply(list) 
gh=pd.DataFrame({'PID':grouped.index, 'RESULT_DATE':grouped.values})
vl=pd.DataFrame(gh.RESULT_DATE.values.tolist()).add_prefix('VL/DATE')

Running this code produces two strings separated by comma within the same column but I want these strings to be separated with two separate columns. So it would have "RESULT" and "DATE" as separated columns and there are 100 columns so looping through columns would be another possibility I think.

Upvotes: 0

Views: 43

Answers (1)

Daniel Seger
Daniel Seger

Reputation: 86

To split one column into two by a separator try this:

df['RESULT_DATE'].str.split(' , ', expand=True)

Upvotes: 1

Related Questions