-
慕容708150
你可以只使用split:pd.DataFrame([y.split(':') for y in x], columns = ['Name','Age', 'Occupation'])输出: Name Age Occupation0 john 42 engineer1 michael 29 doctor
-
守着星空守着你
我会做df = pd.Series(x).str.split(':',expand=True)df.columns = ['Name','Age', 'Occupation']dfOut[172]: Name Age Occupation0 john 42 engineer1 michael 29 doctor
-
忽然笑
不确定这是最好的方法,但是......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 occupation0 john 42 engineer1 michael 29 doctor