I have csv file that looks something like this
x y z
0 a_b_c 30 40
1 d_e_f 50 57
I am trying to modify column x by splitting the string at the first underscore and only keeping the string right before it. Based on this answer I came up with the following solution:
df['x'] = df['x'].map(lambda x: x.str.split('_').str[0])
However, i get an error message
TypeError: only integer scalar arrays can be converted to a scalar index