求赞----求关注
python筛选excel某一列中相同的数据
1.需要cmd下载 pip install pandas 的模板
2.注意文件的路径问题不要出错
3.还有文件的编码格式 ------encoding = 'gbk'
import pandas as pd
#读取excel文件信息
data = pd.read_csv('1.csv',encoding = 'gbk')
#筛选表格中需要的列
data_gender = data[['ID','Price','Actualamount','Merchandise','Time','Place']]
data_gender_re = data_gender[data_gender.notnull()] #除去缺失值
#筛选Place中地点为A 的数据
FF = data_gender_re.loc[(data_gender_re['Place'] == 'A')]
print(data_gender_re.loc[(data_gender_re['Place'] == 'A')])FF.to_csv('C:\\Users\\Administrator\\Desktop\\A.csv',index=False,encoding = 'gbk') #生成excel文件
代码如下:
import pandas as pd
data = pd.read_csv('1.csv',encoding = 'gbk')
data_gender = data[['ID','Price','Actualamount','Merchandise','Time','Place']]
data_gender_re = data_gender[data_gender.notnull()]
FF = data_gender_re.loc[(data_gender_re['Place'] == 'A')]
print(data_gender_re.loc[(data_gender_re['Place'] == 'A')])
FF.to_csv('C:\\Users\\Administrator\\Desktop\\A.csv',index=False,encoding = 'gbk')
需要处理文件如下:
得到的结果如下: