You can first split
columns, create Series
by stack
and remove whitespaces by strip
:
s1 = df.value.str.split(',', expand=True).stack().str.strip().reset_index(level=1, drop=True)
s2 = df.date.str.split(',', expand=True).stack().str.strip().reset_index(level=1, drop=True)
Then concat
both Series
to df1
:
df1 = pd.concat([s1,s2], axis=1, keys=['value','date'])
Remove old columns value
and date
and join
:
print (df.drop(['value','date'], axis=1).join(df1).reset_index(drop=True))
ticker account value date
0 aa assets 100 20121231
1 aa assets 200 20131231
2 bb liabilities 50 20141231
3 bb liabilities 150 20131231
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…