Dataframe split list

CSDN Q & A 2022-05-15 04:47:39 阅读数:490

dataframesplitlist

img

Pictured , about tau This column , I hope I can split it into two columns , One column is

img


The other column is

img


That is, the left side is divided into a column , The right side is divided into a column




Take the answer :
import pandas as pddata = [[768944800,[1,3],0,1.5360], [768944800,[2,4],0,1.5360]]df = pd.DataFrame(data, columns=['0','tau','3','4'])print(df,'\n','-----------------------------------------------')df['tau_left']=[df['tau'][i][0] for i in range(len(df))]df['tau_right']=[df['tau'][i][1] for i in range(len(df))]print(df,'\n','-----------------------------------------------')df_new = pd.DataFrame(df, columns=['0','tau_left','tau_right','3','4'])print(df_new,'\n','-----------------------------------------------')

img


版权声明:本文为[CSDN Q & A]所创,转载请带上原文链接,感谢。 https://primo.wiki/2022/131/202205041636084025.html