(RPA学习)Pandas 删除某列包含特殊字符的行
艺赛旗 RPA9.0全新首发免费下载 点击下载
http://www.i-search.com.cn/index.html?from=line1
详细内容请参看艺赛旗官网支持栏目:RPA社区
点击链接进入 http://support.i-search.com.cn/
1、测试文件(test_data.xlsx)数据如下:
Pandas 删除某列包含特殊字符的行
2、删除账户中文名列中包含 “现金尾箱账户” 的所有行
-- coding: utf-8 --
import pandas as pd
read_data=pd.read_excel(‘test_data.xlsx’) #读取excel表格数据
print(read_data)
read_data=read_data[ ~ read_data[‘账户中文名’].str.contains(‘现金尾箱账户’)] #删除某列包含特殊字符的行
#read_data = read_data[~read_data[‘账户中文名’].isin([‘现金尾箱账户’])] #删除某列包含特殊字符的行
print(read_data)
read_data.to_excel(‘data_all.xls’,index=False) #将数据重新写入excel
输出结果
Pandas 删除某列包含特殊字符的行
将结果写入到新的 excel 文件中(data_all.xls)
Pandas 删除某列包含特殊字符的行