【发布时间】:2014-11-26 17:14:45
【问题描述】:
我有一个熊猫系列,里面充满了这样的字符串:
In:
s = pd.Series(['This is a single line.', 'This is another one.', 'This is a string\nwith more than one line.'])
Out:
0 This is a single line.
1 This is another one.
2 This is a string\nwith more than one line.
dtype: object
如何将本系列中包含换行符 \n 的所有行拆分为各自的行?我期望的是:
0 This is a single line.
1 This is another one.
2 This is a string
3 with more than one line.
dtype: object
我知道我可以用换行符分割每一行
s = s.str.split('\n')
这给了
0 [This is a single line.]
1 [This is another one.]
2 [This is a string, with more than one line.]
但这只会破坏行内的字符串,而不是为每个标记分成自己的行。
【问题讨论】:
标签: python pandas split series