嗨,我有一个这样的数据框:
A B 0: some value [[L1, L2]]
我想将其更改为:
A B 0: some value L1 1: some value L2
我怎样才能做到这一点?
您可以这样操作:
In [84]: df Out[84]: A B 0 some value [[L1, L2]] 1 another value [[L3, L4, L5]] In [85]: (df['B'].apply(lambda x: pd.Series(x[0])) ....: .stack() ....: .reset_index(level=1, drop=True) ....: .to_frame('B') ....: .join(df[['A']], how='left') ....: ) Out[85]: B A 0 L1 some value 0 L2 some value 1 L3 another value 1 L4 another value 1 L5 another value