hi i have string in one column : s='123. 125. 200.' i want to split it to 3 columns(or as many numbers i have ends with .) To separate columns and that it will be number not string !, in every column .
Asked
Active
Viewed 57 times
2
-
You can use `str.split` as explained in [this answer](https://stackoverflow.com/questions/37333299/splitting-a-column-by-delimiter-pandas-python). `to_numeric` can help you convert to int, as explained [here](https://stackoverflow.com/questions/42719749/pandas-convert-string-to-int). – Jonny5 Dec 28 '19 at 18:00
1 Answers
4
From what I understand, you can use:
s='123. 125. 200.'
pd.Series(s).str.rstrip('.').str.split('.',expand=True).apply(pd.to_numeric,errors='coerce')
0 1 2
0 123 125 200

anky
- 74,114
- 11
- 41
- 70
-
maybe clarify that the `rstrip` will remove the last `.` and that `expand` will create new columns based on the split token (`.`)? OP asked for numbers, I think `to_numeric` would do the trick, right? – Jonny5 Dec 28 '19 at 18:01