I have a data frame with a single column 'data' which contains words separated by space. I want to separate the data into multiple rows split by space. I have tried the following code but does not work:
from itertools import chain
def chainer(s):
return list(chain.from_iterable(s.str.split('\s+')))
lengths = df['data'].str.split('\s+').map(len)
df_m = pd.DataFrame({"data" : np.repeat(df["data"], lengths)})
Dataframe example
words = ["a b c d e","b m g f e","c" ,"w"]
dff = pd.DataFrame({"data" :words })
data
0 a b c d e
1 b m g f e
2 c
3 w
dffis not what you want?