从熊猫列中的列表中删除hars

时间:2020-10-14 12:01:58

标签: python pandas dataframe replace remove

我有一个熊猫数据框架df,其中有两列(NACEcleaned),看起来像这样:

    NACE     cleaned
0   071 [260111, 260112]
1   072 [2603, 2604, 2606, 261610, 261690, 2607, 2608]
2   081 [251511, 251512, 251520, 251611, 251612, 25162]
3   089 [251010, 251020, 2502, 25030010, 251110, 25112]
4   101 [020110, 02012020, 02012030a), 02012050, 020130]
... ... ...
92  324 [95030021, 95030041, 95030049, 95030029, 95030]
93  325 [901841, 90184910, 90184990b), 841920, 90183110]
94  329 [960310, 96039010, 96039091, 96039099, 960321]
95  331 [-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-, 983843]
96  332 [-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-]

cleaned列由字符串列表组成,其中有些仍然包含需要删除的字符。具体来说,我需要删除所有+-)

为了专注于其中一种+,我尝试了许多方法,包括:

df['cleaned'] = df['cleaned'].str.replace('+', '')

而且:

df.replace('+', '', regex = True, inplace = True)

和一个绝望的:

for i in df['cleaned']:
    for x in i:
        i.replace('+', '')

这些解决方案的不同版本适用于大多数数据帧,但当列由列表组成时则不行。 我在这里需要帮助。谢谢。

0 个答案:

没有答案