pandas读取csv文件中的问题:如何将BP列中的数据以/为界拆分为两组数据并重新生成两列数据

img


import pandas as pd

df = pd.DataFrame(data = {'height': [167.5, 170], 'weight': [73.8, 61], "BP": ['126/81', '138/92']})
print(df)

df[['col1', 'col2']] = df['BP'].str.split("/", n = 1, expand = True)
print(df)

'''--result
   height  weight      BP
0   167.5    73.8  126/81
1   170.0    61.0  138/92
   height  weight      BP col1 col2
0   167.5    73.8  126/81  126   81
1   170.0    61.0  138/92  138   92
'''