1 回答

TA貢獻(xiàn)1790條經(jīng)驗(yàn) 獲得超9個(gè)贊
您可以查看所有Exp以正則表達(dá)式開頭的列(^用于字符串的開頭) by DataFrame.filter,然后調(diào)用value_countswithDataFrame.apply并最后將NaNs轉(zhuǎn)換為0with 轉(zhuǎn)換為整數(shù):
df = data.filter(regex='^Exp').apply(pd.value_counts).fillna(0).astype(int)
print (df)
Exp ABAP Exp Autre Exp Python
1 an de pratique 0 1 0
1 semestre de pratique 2 0 4
Aucune expérience 4 5 2
編輯:
df = (data.filter(regex='^App')
.stack()
.str.split(',;\s+', expand=True)
.stack()
.groupby(level=1)
.value_counts()
.unstack(0, fill_value=0)
)
print (df)
App ABAP App Autre App Python
Aucune expérience 4 5 2
dans un autre cadre 0 0 1
en Bachelor 2 1 4
en Terminale 0 0 1
添加回答
舉報(bào)