I have a pandas data frame like df named column_name
construct_name
aaaa_t1_2
cccc_t4_10
bbbb_g3_3
etc. I want to first break all the names underlined and save the first element (aaaa, cccc, etc.) as another column name.
Expected Result
construct_name name
aaaa_t1_2 aaaa
cccc_t4_10 bbbb
etc.
I tried the following
df['construct_name'].map(lambda row:row.split("_"))and it gives me a list like
[aaaa,t1,2]
[cccc,t4,10]
etc.
But when I do
df['construct_name'].map(lambda row:row.split("_"))[0], to get the first element of the list, I get an error. Can you suggest a fix. Thanks
Ssank source
share