在python中用逗号分割

时间:2018-04-10 07:18:05

标签: python pandas

我在数据框中有以下数据

           From                        To
          [time]                       clock time
          [year]                       twelvemonth, yr
          [people]                     None
          [way]                        means, agency
          [lily]                       flower
          [man]                        homo, human being, human
          [man]                        adult male, male
          [case]                       instance, example
          [case]                       lawsuit, suit, cause, causa
          [case]                       display case, showcase, vitrine

我想要的是将它从 TO 列中的“,”拆分,并为每个条目创建单独的行,以便预期的输出

               From                        To
              [time]                       clock time
              [year]                       twelvemonth
              [year]                       yr
              [people]                     None
              [way]                        means
              [way]                        agency
              [lily]                       flower
              [man]                        homo
              [man]                        human being
              [man]                        human
              [man]                        adult male
              [man]                        male
              [case]                       instance
              [case]                       example
              [case]                       lawsuit
              [case]                       suit
              [case]                       cause
              [case]                       causa                              
              [case]                       display case
              [case]                       showcase
              [case]                       vitrine

我的数据采用Dataframe格式 我试过这个,但这没有帮助

b = pd.concat([pd.Series(row['From'], row['To'].split(','))
               for _, row in df.iterrows()]).reset_index()

任何人都可以帮忙吗?

0 个答案:

没有答案