It is impossible, because you would turn out with an extra row in you dataframe without an index value. The definition of a dataframe does not support what I believe you are trying to achieve Two-dimensional size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns).
Which I believe looks like this:
A
0 option2
blablabla
1 option2
blablabla
2 option2
blablabla
3 option2
blablabla
4 option2
blablabla
As a solution you can try and split into two columns and add an extra column that would flag where a line break should appear so when you concatenate the full row, you would get a string of what you want:
import spintax
import pandas as pd
df = pd.DataFrame()
for i in range(0, 50):
data = spintax.spin("{option1|option2}" + "\n" +" blablabla ")
df = df.append({'A': data}, ignore_index=True)
df['A'] = df['A'].str.replace(r'\s+', " ")
print(df)
df['split'] = df['A'].str.split(' ')
df['first'] = df['split'].str.get(0)
df['flag_break'] = '\n'
df['second'] = df['split'].str.get(1)
df['full_string'] = df['first'] + " " +df['flag_break']+df['second']
df = df.drop('split',axis=1)
print(df.head())
print(df['full_string'].max())
Output of your dataframe:
A first flag_break second full_string
0 option2 blablabla option2 \n blablabla option2 \nblablabla
1 option1 blablabla option1 \n blablabla option1 \nblablabla
2 option2 blablabla option2 \n blablabla option2 \nblablabla
3 option1 blablabla option1 \n blablabla option1 \nblablabla
4 option2 blablabla option2 \n blablabla option2 \nblablabla
Output of your full string, so that you get the line break print(df['full_string'].max())
:
option2
blablabla