-1

I want to take a DF column and build new column based on str splitting.
Column values looks like that: abcd <> 1234

In order to split i'm using the following:

df['user_id'] = df['Customer User Id'].str.split('<>').str.get(1)

This action works but i'm getting red window saying: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead

Tried to replace the code with loc:

df['user_id'] = df.loc[:,['Customer User Id']]['Customer User Id'].str.split('<>|<').str.get(1)

but the error still shows

Any suggestions..

Joe T. Boka
  • 6,554
  • 6
  • 29
  • 48
mrgold
  • 1
  • 1

1 Answers1

0

I am using this kind of data:

key1  key2  
22    abcd <> 1234  
34    abcd <> 1234  
12    abcd <> 1234  
55    abcd <> 1234

And the code is:

my_df["key3"] = my_df['key2'].str.split('<>').str.get(1)

Output is :

key1    key2    key3
22  abcd <> 1234    1234
34  abcd <> 1234    1234
12  abcd <> 1234    1234
55  abcd <> 1234    1234
Rohan Amrute
  • 764
  • 1
  • 9
  • 23