I have a set of data like:
0 1
0 type 1 type 2
1 type 3 type 4
How can I transfer it to:
0 1
0 1 2
1 3 4
perfer using applyor transform function
Yoou can use DataFrame.replace:
print (df.replace({'type ': ''}, regex=True))
0 1
0 1 2
1 3 4
>>> df.apply(lambda x: x.str.replace('type ','').astype(int))
0 1
0 1 2
1 3 4
remove the .astype(int) if you don't need to convert to int
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With