将 win-lose-draw 和有时 NC 形式的记录列拆分为 4 个单独的列

split record columns of the form win-lose-draw and sometimes NC into 4 separate columns

我的数据框有一个列 'record',大部分时间看起来像 10-3-0,但有时它也包括无比赛“35-11-2 (1 NC)”

我想将此列拆分为 4 个单独的列“win”“lose”“draw”“nc”当记录列中没有 NC 指示时,nc 取 None 作为值

df_test = pd.DataFrame(data={'records':["35-11-2 (1 NC)", "30-11-12 (2 NC)", "20-11-2"]})
df_test['records'] = df_test['records'].str.replace(' \(', '-(', regex=True)
print(df_test)
df_test[['win', 'lose', 'draw', 'nc']] = df_test['records'].str.split('-', expand=True)
print(df_test)