python - 使用正则表达式从许多列名中删除句点
问题描述
我想删除一个'。使用正则表达式从列名中提取代码,并希望将代码应用于许多以“。”结尾的列名,以便可以将每对同名列合并为一个。
例如,列名“Fund”和“Fund”。不同,有不同的价值,但应该只是“基金”。
为此使用的最佳正则表达式是什么?
解决方案
尝试这个:
df = pd.DataFrame([1], columns=['Fund.'])
df.columns = df.columns.str.replace('.','')
输出:
print(df.columns)
Index(['Fund'], dtype='object')
推荐阅读
- r - r脚本中的for循环数据框
- android - 当服务想要停止时应用程序崩溃
- java - java时间戳格式 - 在单行解决方案中避免子字符串IndexException
- javascript - 将javascript注入iframe时的时间问题
- python - python中的类声明,参数中有或没有对象
- applescript - 将 Applications 文件夹中所有应用程序的列表保存到文本文件
- mysql - sq,每天唯一的第一个值
- visual-studio-code - 如何在vscode中包围颤振小部件
- kentico - 启用多个页面别名
- node.js - 注册快速中间件的最佳做法是什么?