用pandas处理excel表格

# -*- coding: UTF-8 -*-
import pandas as pd
import csv
d1 = pd.read_excel('jijin.xlsx', header=0)
def panduan(s,lines):
    for ord,data in enumerate(lines):
        d = data.split(',')
        i = int(d[0])
        if s == i:
            break
        else:
            if ord == 459:
                print 's:  ',s
                return True
            # d1.drop(x, axis = 0,inplace = True)
    return False
with open('sharp.txt','r') as f:
    lines = f.readlines()
    a = 0
    b = 0
    for x,c in enumerate(d1['Symbol']):
        if b == c:
            pass
        else:
            if a == c:
                d1.drop(x, axis = 0,inplace = True)
            else:
                result = panduan(c,lines)
                if result:
                    d1.drop(x, axis = 0,inplace = True) 
                    a = c
                else:
                    b = c   

# print d1
d1.to_excel('save_data.xlsx')

比较两个文件,另一个文件里面没有的则删除,最后保存

你可能感兴趣的:(pandas)