开发者社区 问答 正文

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

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

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 515 分享
分享
版权
举报
1 条回答
写回答
取消 提交回答
  • 这个我觉得可以结合pandas库去定义数据库,再转化成二维数组

    2020-03-25 16:39:20 举报
    赞同 评论

    评论

    全部评论 (0)

    登录后可评论
问答地址:
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等