python笔记10:数据处理之去除空格

# -*- coding: utf-8 -*-
#strip函数作用:清除字符型数据左右的空格。
#strip函数语法:strip

from pandas import read_csv

df = read_csv("D:/python/workspace/pythonStudy/10.csv")

newName = df['key'].str.lstrip() #去除左边的空格

newName = df['key'].str.rstrip() #去除右边的空格

newName = df['key'].str.strip() #去除两边的空格

df['key'] = newName  #替换以前的列

猜你喜欢

转载自blog.csdn.net/aiyo92/article/details/86495317