I am working on a dataframe which contains "_" on each row, eg:
numbers
0 123
1 321_2
2 2222_2
3 41232_1
4 23123_5
5 45455
6 231231
7 3479_23_23
8 82837_212_fd
My purpose is to remove all the string after first '_' for each row, eg:
numbers
0 123
1 321
2 2222
3 41232
4 23123
5 45455
6 231231
7 3479
8 82837
then I got an idea using 'split' function:
result = s.split("_")[0]
However, it cannot apply to the dataframe since I got an error: AttributeError: 'DataFrame' object has no attribute 'split'
My first question is that: How can I remove str after first '_'?
Moreover, is it possible to just remove '_' but keep the leading number part?
s.str.split('_')[0]ors.numbers.str.split('_')[0]. See here for the string methods