我想将权重的数量分成很多列,其中包含其确切的权重。
我试图用','分割并创建了sucesfull列df ['weight20'],现在我想创建weight30,weight40,weight 10之类的列。
import pandas as pd
df = pd.read_csv('weight.csv', delimiter=";", index_col=False)
df.head()
df['weight'] = df['weight'].str.split(',')
def splitnum(num):
for i in num:
if i == '20':
return '20'
else:
'0'
df['weight20'] = df['weight'].apply(splitnum)
希望您对df ['weight30'],df ['weight10']列有帮助, df ['weight40'],
这是我的小型数据集:
谢谢!