开发者社区> 问答> 正文

如何生成满足某些要求的列的列表

我有一个函数来规范列标题基于一些规则。 代码如下:

def content_normalize(df):
    '''
    This funcion performs the following steps on the textual columns of a dataframe:
    1 - Remove leading and trailing white spaces from columns that starts with [ cd_ , nm_ ];
    2 - Update all cd_ column's contents to lowercase and apply unidecode (remove accents and special characters)

    Parameters:
    A dataframe

    Return:
    A normalized dataframe

    '''
    for coluna in df.columns:
        if df[coluna].dtype=='O':
            if coluna.startswith(('nm_', 'cd_')):
                df[coluna]=df[coluna].str.strip()
                if coluna.startswith('cd_'):
                    df.loc[df[coluna].notnull(),coluna]=df.loc[df[coluna].notnull(),coluna].apply(lambda x : unidecode(x))
                    df[coluna]=df[coluna].str.lower()
    return df

现在我需要创建另一个函数来显示未规范化的列列表。如何在不规格化列的情况下生成列表? 问题来源StackOverflow 地址:/questions/59378943/how-to-generate-a-list-of-columns-that-meet-some-requirements

展开
收起
kun坤 2019-12-30 09:57:56 492 0
1 条回答
写回答
取消 提交回答
  • 这个我觉得可以结合pandas库去定义数据库,再转化成二维数组

    2020-03-25 16:39:20
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载