【发布时间】:2021-01-24 06:29:09
【问题描述】:
假设我有一个数据框列 df.info():
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Action_3.@source 1 non-null object
1 Description_3.#text 1 non-null object
2 Code_3.@source 1 non-null object
3 Others 1 non-null object
4 Animal_1 1 non-null object
收件人:
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Action.@source_3 1 non-null object
1 Description.#text_3 1 non-null object
2 Code.@source_3 1 non-null object
3 Others 1 non-null object
4 Animal_1 1 non-null object
这需要动态完成。我的计划是:
- 使用正则表达式查找字符串中间的数字。
- 将
_{digit}替换为列名的后面,反复进行。
我当前的代码:
def check_number_in_column(column_name):
return any(i.isdigit() for i in column_name)
# List out the column names then loop
temp_column_name = temp_df.columns
for j, name in enumerate(temp_column_name):
if check_number_in_column(name) is True :
#TODO
【问题讨论】:
标签: python pandas dataframe rename