熊猫:从数据框中的列中删除空格

时间:2018-09-11 13:50:33

标签: python pandas removing-whitespace

我正在尝试从我的数据框中删除多个空格,也称为空格。

df = pd.read_csv(Location + sicht_orig, delimiter = ';', encoding = "ISO-8859-1", decimal = ",", error_bad_lines=False)

请确保我具有数据类型“对象”,即字符串:

print(df['column_name'].dtypes)

现在,我使用strip删除空白:

df['column_name'] = df['column_name'].str.strip()
print(df['column_name']) 

可悲的是,所有空白仍然存在。

替代方法:

print (getattr (row, "Description").str.strip('  '))

给予:

AttributeError: 'str' object has no attribute 'str'

我也尝试了失败:

df['Description'] = df['Description'].apply(lambda x: x.str.strip())

任何对我的初学者的想法都将不胜感激。

0 个答案:

没有答案