使用 pandas 阅读excel时如何删除上标? [英] How could I remove the superscript when I read excel using pandas?

查看:113
本文介绍了使用 pandas 阅读excel时如何删除上标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文件在这里我想读取一个Excel文件使用大熊猫.一些数据中带有上标.当我使用pd.read_excel()读取文件时,上标数字就会出现.我该怎么做才能删除号码?

the file is hereI want to read an excel file using pandas. Some of the data have superscript in it. And when I use pd.read_excel() to read the file, the superscript numbers just appear. What should I do to remove the numbers?

例如,当数据为带有上标13的USA时,我从熊猫获得的结果为USA13.我只想从中删除13个,改为获取美国.

For example, when the data is USA with superscript 13, the result I get from pandas is USA13. I just want to remove 13 from it and get USA instead.

推荐答案

import string
energy['Country'] = energy['Country'].apply(lambda x: x.strip(string.digits))

看来这对我来说很好.

这篇关于使用 pandas 阅读excel时如何删除上标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆