pandas-text data split

Insert picture description here

# 将航班经过的地点进行分割
df['Location'].str.split(', ').head()

Insert picture description here

# 使用expand
df['Location'].str.split(', ', expand=True).head()

Insert picture description here

# 使用n
df['Location'].str.split(', ', expand=True, n=1).head()

Insert picture description here
Only when expand is False, can you use str[] or str.get() to get data

# 获取分割的结果
df['Location'].str.split(', ').str.get(0).head()

Insert picture description here

df['Location'].str.split(', ').str[1].head()

Insert picture description here

Guess you like

Origin blog.csdn.net/lildn/article/details/114707735