0

I have a Series of strings in which the format is date;value;value.

I can't use a basic

data.str.slice(stop=7)

as the values can vary in length.


Does anyone have any suggestions for how to slice these stings into 3 columns?

Example:

2008-01;12.759358;6.297382

2008-06;17.44426;8.890847

Thanks!

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57

2 Answers2

2

Try

"string0;string1;string2".split(';')

Further reading:
https://python-reference.readthedocs.io/en/latest/docs/str/split.html

  • This question asks how to split a [`pandas.Series`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.html#pandas-series) into multiple columns. Not how to split a single python string into a list. This does not answer this question. – Henry Ecker May 27 '21 at 13:43
0

This should work:

raw_string = 2008-01;12.759358;6.297382
formatted = raw_string.split(';')
H4KKR
  • 64
  • 1
  • 8