In [1]: print(type(ebola_melt))
<class 'pandas.core.frame.DataFrame'>
In [2]: ebola_melt['str_split'] = ebola_melt['type_country']
.str.split('_')
In [3]: print(type(ebola_melt['str_split']))
<class 'pandas.core.series.Series'>
应用了.str方法的 In [4]: ebola_melt['str_split'].str.get(0)
Out[4]:
0 Cases
1 Cases
2 Cases
3 Cases
4 Cases
...
In [5]: ebola_melt['str_split'].get(0)
Out[5]: ['Cases', 'Guinea']
答案 0 :(得分:0)
pandas.Series.str.get从Series / Index中的列表中提取元素。
pandas.Series.get从对象获取给定索引值的项目
请参阅文档 https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.get.html 和 https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.get.html
所以,
ebola_melt['str_split'] #contains ['Cases', 'Guinea']
ebola_melt['str_split'].str.get(0) #returns the values present in the zeorth index of all rows which is Cases
ebola_melt['str_split'].get(0) #returns the row present in the zeorth index
ebola_melt['str_split'].get #returns the all the rows