0

After extracting strings using extract_df = pd.str.extract('(\w+)\d+(\w+)', expand =True) I get new dataframe with columns named 0 and 1.

I want to merge it back to my original dataframe with specific column names.

I thought I could generate multiple columns using .loc method, such as data.loc[:,['name1','name2']] = extract_df but it did not work.

I know I can change the column names and use pd.merge or join method but it seems inefficient to me.

Is there a nice way to generate multiple columns using .loc?

Or is there any other efficient way to handle this? Thanks.

Matthew Son
  • 1,109
  • 8
  • 27

0 Answers0