我在用破折号分割熊猫系列时遇到问题:
df['age'].head()
75)[1]Reichenberg, Sudetenland, Germany (present-day Liberec
52) orJanuary 20, 1967 (age 51)(sources differ
45–46
40–41
52)St.Thomas, Virgin Islands (United States of America
申请时:
df['age'] = df['age'].str.split(')', n=1, expand=True)[0]
我正确地得到:
df['age'].head()
75
52
45–46
40–41
52
但是当我尝试用破折号分割时,它不会分割结果:
df['age'] = df['age'].str.split('-', n=1, expand=True)[0]
df['age'].head()
75
52
45–46
40–41
52