Python 如果满足条件,如何将一个数据帧行拆分为多个数据帧行?
我有一个数据帧Python 如果满足条件,如何将一个数据帧行拆分为多个数据帧行?,python,python-3.x,pandas,dataframe,numpy,Python,Python 3.x,Pandas,Dataframe,Numpy,我有一个数据帧 Description 0 Hi there 1 He is my family. 2 He studies in the United States. 我希望在这种情况下拆分此数据帧:如果描述长度超过10个字符,则其余字符应位于下一行 预期产出: Description 0 Hi there 1 He is my f 2 a
Description
0 Hi there
1 He is my family.
2 He studies in the United States.
我希望在这种情况下拆分此数据帧:如果描述长度超过10个字符,则其余字符应位于下一行
预期产出:
Description
0 Hi there
1 He is my f
2 amily.
3 He studies
4 in the Uni
5 ted States
6 .
在中使用自定义lambda,然后:
单向使用pandas.Series.str.findall:
df["Description"].str.findall(".{1,10}").explode()
输出:
0 Hi there
1 He is my f
1 amily.
2 He studies
2 in the Un
2 ited State
2 s.
Name: Description, dtype: object
嗨,耶斯雷尔,如果你能在这件事上帮助我,那就太好了
0 Hi there
1 He is my f
1 amily.
2 He studies
2 in the Un
2 ited State
2 s.
Name: Description, dtype: object