0

I have an .xlsx file which has 13 columns. I need to extract/copy text from a string in one column specifically into a new column. The string in the column is structured with underscore (_) delimiters:

TextA_TextB - TextB_TextC_TextD_TextE_TextF

I need to copy the TextA specifically into a new column. What would be the best approach here?

P Patel
  • 1
  • 1

1 Answers1

0

You could try this.

Once you have the column in a DataFrame

In [30]: df
Out[30]: 
                        a
0  test1_test2_tes3_test4

In [31]: df['a'] = df['a'].apply(lambda x: x.split('_'))

In [33]: df = pd.concat([df, df['a'].apply(pd.Series)], axis=1)

In [34]: df
Out[34]: 
                             a      0      1     2      3
0  [test1, test2, tes3, test4]  test1  test2  tes3  test4
Praveen
  • 2,137
  • 1
  • 18
  • 21