Sco*_*son 1 python dataframe pandas
如果我有以下数据框“国家”:
country info
england london-europe
scotland edinburgh-europe
china beijing-asia
unitedstates washington-north_america
Run Code Online (Sandbox Code Playgroud)
我想获取信息字段,并且必须删除“-”之后的所有内容,变为:
country info
england london
scotland edinburgh
china beijing
unitedstates washington
Run Code Online (Sandbox Code Playgroud)
我该怎么做呢?
尝试:
countries['info'] = countries['info'].str.split('-').str[0]
Run Code Online (Sandbox Code Playgroud)
输出:
country info
0 england london
1 scotland edinburgh
2 china beijing
3 unitedstates washington
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
48 次 |
| 最近记录: |