注意:运行代码的时候请关闭 excel 文件。
# read excel and filter the number with regular expressionimport pandas as pdimport redf = pd.read_excel('D:\\健康养生\\217种常见食物的嘌呤含量表.xlsx')# print(df)# print(df['foodName'])for i in df['foodName']:new_str = re.sub('[0-9]', '', i) # substitute 将数字替换为无字符print(new_str)
正则表达式请参考
/python3/python3-reg-expressions.html