【发布时间】:2020-11-09 13:02:23
【问题描述】:
我有以下代码,如果字符串或数字中有括号,我想替换国家名称,我们必须删除它 例如 'Bolivia (Plurinational State of)' 应该是 'Bolivia', 'Switzerland17' 应该是 'Switzerland'。
import pandas as pd
from pandas import ExcelWriter
from pandas import ExcelFile
pd.set_option('display.max_columns',None)
pd.set_option('display.max_rows',None)
df=pd.read_excel('Energy Indicators.xls',skiprows=17, skipfooter=265-(227))
df.drop(df.columns[[0,1]], axis=1, inplace=True)
df.columns=['Country', 'Energy Supply', 'Energy Supply per Capita', '% Renewable']
【问题讨论】:
标签: pandas string dataframe rename