问题描述
all_data['Title']= all_data['Name'].str.split(',',expand=True)[1].str.split('.',expand=True)[0]
任何人都可以解释这行代码的含义吗?尤其是expand=True
和[1]
[0]
。
解决方法
在这里看看:pandas.Series.str.split
将拆分的字符串扩展为单独的列。
如果为True,则返回DataFrame / MultiIndex扩展维。
如果为False,则返回包含字符串列表的Series / Index。
s = pd.Series(
[
"this is a regular sentence",]
)
s.str.split(expand=True)
0 1 2 3 4
这是一个普通的句子