怎么给pandas DataFrame 格式的数据其中的列分成两列或者多列呢
用df.map() 和str.split()两个内置函数
例如:
1 import pandas as pd 2 df = pd.DataFrame({'dateTime':['2021-02-01 10:10:21','2022-03-01 12:23:22','2022-08-15 13:10:22'],'id':['001','002','003'],'money':[34,43,54]}) 3 print(df) 4 df['date'] = df['dateTime'].map(lambda x:x.split(' ')[0]) 5 df['time'] = df['dateTime'].map(lambda x:x.split(' ')[1]) 6 df = df[['date','time','id','money']] 7 print(df)
运行结果:
标签:map,10,python,DataFrame,df,split,pandas From: https://www.cnblogs.com/szeto/p/16587962.html