Reputation: 17
I am trying to split my df every 3 rows OR by the \n delimiter. The df looks as follows:
I have attempted string replace but I would like to keep the index after the split occurs. Please help
Upvotes: 0
Views: 41
Reputation: 2624
Use str accessor as follows.
for i in range(3, df.columns, 3):
df.drop(i, axis = 1, inplace = True) # remove column i
df = pd.concat(df, df[i].str.split('\n', expand = True), axis = 1)
Upvotes: 1