20220402help

 1 import xlrd
 2 import xlsxwriter
 3 import os
 4 import pandas as pd
 5 
 6 # 文件夹名称
 7 path = "linshi/"
 8 
 9 # 获取文件目录
10 files = os.listdir(path)
11 print(files)
12 
13 print(len(files))
14 
15 # 读取第一个表格
16 data = pd.read_excel(path + files[0]
17               #, index_col=0
18              )
19 #data.head()
20 
21 df = data.copy()
22 
23 # 获得列表,为空行的人名
24 
25 # name0 = df[df["学科"].isnull()]["name"].reset_index()
26 name0 = df[df["前收盘价(元)"].isnull()]["简称"].reset_index()
27 name1 = df[df["换手率(%)"].isnull()]["简称"].reset_index()
28 #print(name0)
29 #print(name1)
30 name0_1 = []
31 name1_1 = []
32 for i in range(len(name0)):
33     name0_1.append(name0["简称"][i])
34     print(name0["简称"][i])
35 
36 for i in range(len(name1)):
37     name1_1.append(name1["简称"][i])
38     print(name1["简称"][i])
39 
40 # 存放指定名称的列表,去重
41 list_name = list(set(name0_1).union(set(name1_1)))
42 print(list_name)
43 '''
44 for i in range(len(name0)):
45     list_name.append(name0["简称"][i])
46     print(name0["简称"][i])
47 '''
48 
49 # 指定name的索引
50 
51 indexNames=df[df['简称'].isin(list_name)].index
52 # data.query('a==1 | a==2')
53 # indexNames
54 
55 # 
56 
57 df = df.drop(indexNames).reset_index()
58 df.to_excel(path+"xin.xlsx", index=False)

 

posted on 2022-06-23 09:20  cookie的笔记簿  阅读(18)  评论(0编辑  收藏  举报