0

Variable c3 stored the arraylist I would like to split a column in the dataframe named df3 into two columns.

c3 = Retrieve_ED_Notes.arr_cat3
df3 = pd.DataFrame(np.array(c3), columns=["content"]).drop_duplicates()
print(df3)

I would like to make 3 in a column and 85 Male Malay..... into another column. The out put of the dataframe, df3 looks like this:

                                                                  content
0  3 85 Male Malay  NKDA walking stick at home, and ambulant with WS to void deck able to walk to B...
1  3 85yo chinese man nkda PHX 1) Hypertension 2) Hyperlipidemia 3) Benign prostatic hyperplasia 4)...
  • 4
    Possible duplicate of [How to split a column into two columns?](https://stackoverflow.com/questions/14745022/how-to-split-a-column-into-two-columns) – rocarvaj Sep 20 '18 at 03:31

1 Answers1

0

Hope this works!

df3['content_1'] = df3['content'].apply(lambda x: x.split(' ')[0])
df3['content_2'] = df3['content'].apply(lambda x: ' '.join(x.split(' ')[1:]))
Arihant
  • 735
  • 5
  • 14
  • This keeps the original 'content' column and adds 2 more columns by the split, it doesn't split the original df into 2 columns. – d_kennetz Sep 20 '18 at 03:23
  • yes @d_kennetz. you are right. I just didn't want to use `pd.DataFrame`. Your solution seems to provide the required columns alone. And I think your's is the way of doing string split in pandas dataframe. Thanks for sharing. – Arihant Sep 20 '18 at 03:25