3 回答
TA贡献1831条经验 获得超4个赞
你可以只使用split:
pd.DataFrame([y.split(':') for y in x], columns = ['Name','Age', 'Occupation'])
输出:
Name Age Occupation
0 john 42 engineer
1 michael 29 doctor
TA贡献1799条经验 获得超8个赞
我会做
df = pd.Series(x).str.split(':',expand=True)
df.columns = ['Name','Age', 'Occupation']
df
Out[172]:
Name Age Occupation
0 john 42 engineer
1 michael 29 doctor
TA贡献1806条经验 获得超5个赞
不确定这是最好的方法,但是......
x = ['john:42:engineer', 'michael:29:doctor']
x = [i.split(':') for i in x]
pd.DataFrame({'name': [i[0] for i in x], 'age': [i[2] for i in x], 'occupation': [i[1] for i in x]})
Output:
name age occupation
0 john 42 engineer
1 michael 29 doctor
添加回答
举报