数据
Metropolitan area Population (2016 est.)[8] NHL
0 New York 20153634 RangersIslandersDevils
1 Los Angeles 13310447 KingsDucks
2 San Jose 6657982 Sharks
3 Chicago 9512999 Blackhawks
我希望输出为:
Metropolitan area Population (2016 est.)[8] NHL
0 New York 20153634 ['Rangers','Islanders','Devils']
1 Los Angeles 13310447 ['Kings','Ducks']
2 San Jose 6657982 Sharks
3 Chicago 9512999 Blackhawks
我希望这些字符串在列表中,以便以后可以使用explode()。请帮助
答案 0 :(得分:2)
您可以split
使用正向预测的正则表达式:
df['NHL'].str.split('[a-z](?=[A-Z])')
输出:
0 [Ranger, Islander, Devils]
1 [King, Ducks]
2 [Sharks]
3 [Blackhawks]
模式'[a-z](?=[A-Z])'
查找所有小写字母,后跟大写字母。