回答編集履歴

1

重複

2021/09/09 03:48

投稿

F91_
F91_

スコア16

test CHANGED
@@ -1,169 +1 @@
1
- ```python
2
-
3
- import pandas as pd
4
-
5
- from openpyxl import Workbook
6
-
7
- import glob
8
-
9
-
10
-
11
- t=input('更新したい月を入力してくださ')
1
+ 重複てしまいましが、削除が出来なので残ってまっています。
12
-
13
- file_list1=glob.glob('//192.168.3.141/pi/mydata'+t+'*')
14
-
15
- file_list2=glob.glob('//192.168.3.140/pi/mydata'+t+'*')
16
-
17
- file_list3=glob.glob('//192.168.3.139/pi/mydata'+t+'*')
18
-
19
- file_list4=glob.glob('//192.168.3.135/pi/mydata'+t+'*')
20
-
21
- file_list5=glob.glob('//192.168.3.132/pi/mydata'+t+'*')
22
-
23
- file_list6=glob.glob('//192.168.3.131/pi/mydata'+t+'*')
24
-
25
- file_list7=glob.glob('//192.168.3.134/pi/mydata'+t+'*')
26
-
27
-
28
-
29
- rcd1={'日付' : [], '稼働時間(分)': [], '無人稼働時間(分)': [], '停止時間(分)': [],'トータル時間(分)': [],'稼働率(%)': []}
30
-
31
-
32
-
33
- for file1 in file_list1:
34
-
35
-
36
-
37
- a1=pd.read_csv(file1)
38
-
39
- d1=(file1[25:33])
40
-
41
- x1=a1.iloc[:,0].count()
42
-
43
- y1=a1.iloc[:,1].sum()
44
-
45
- z1=a1.iloc[:,2].sum()
46
-
47
- u1=x1-y1-z1
48
-
49
- w1=round(y1/x1*100,1)
50
-
51
- rcd1['日付'].append(d1)
52
-
53
- rcd1['稼働時間(分)'].append(y1)
54
-
55
- rcd1['無人稼働時間(分)'].append(z1)
56
-
57
- rcd1['停止時間(分)'].append(u1)
58
-
59
- rcd1['トータル時間(分)'].append(x1)
60
-
61
- rcd1['稼働率(%)'].append(w1)
62
-
63
-
64
-
65
- df1=pd.DataFrame(rcd1)
66
-
67
- print(df1)
68
-
69
- g1='全機稼働率'
70
-
71
-
72
-
73
- monthly_file =g1+ f'{t}.xlsx'
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
- rcd2={'日付' : [], '稼働時間(分)': [], '無人稼働時間(分)': [], '停止時間(分)': [],'トータル時間(分)': [],'稼働率(%)': []}
88
-
89
-
90
-
91
- for file2 in file_list2:
92
-
93
-
94
-
95
- a2=pd.read_csv(file2)
96
-
97
- d2=(file2[25:33])
98
-
99
- x2=a2.iloc[:,0].count()
100
-
101
- y2=a2.iloc[:,1].sum()
102
-
103
- z2=a2.iloc[:,2].sum()
104
-
105
- u2=x2-y2-z2
106
-
107
- w2=round(y2/x2*100,1)
108
-
109
- rcd2['日付'].append(d2)
110
-
111
- rcd2['稼働時間(分)'].append(y2)
112
-
113
- rcd2['無人稼働時間(分)'].append(z2)
114
-
115
- rcd2['停止時間(分)'].append(u2)
116
-
117
- rcd2['トータル時間(分)'].append(x2)
118
-
119
- rcd2['稼働率(%)'].append(w2)
120
-
121
-
122
-
123
- df2=pd.DataFrame(rcd2)
124
-
125
- print(df2)
126
-
127
-
128
-
129
- try:
130
-
131
- df_m1 = pd.read_excel(monthly_file,dtype={'日付': str})
132
-
133
- df_output1 = pd.merge(df_m1, df1,how='outer')
134
-
135
- except FileNotFoundError:
136
-
137
- df_output1 = df1.copy()
138
-
139
- df_output1['コメント'] = None
140
-
141
-
142
-
143
- try:
144
-
145
- df_m2 = pd.read_excel(monthly_file,dtype={'日付': str})
146
-
147
- df_output2 = pd.merge(df_m2, df2,how='outer')
148
-
149
- except FileNotFoundError:
150
-
151
- df_output2 = df2.copy()
152
-
153
- df_output2['コメント'] = None
154
-
155
-
156
-
157
- #df_output1.to_excel('//192.168.3.225/Share\石岡工場/INV推進室\機械導入PJ/IOT/'+monthly_file1,sheet_name='D31',index=False)
158
-
159
- #df_output2.to_excel('//192.168.3.225/Share\石岡工場/INV推進室\機械導入PJ/IOT/'+monthly_file1,sheet_name='D32',index=False)
160
-
161
-
162
-
163
- with pd.ExcelWriter('//192.168.3.225/Share\石岡工場/INV推進室\機械導入PJ/IOT/'+monthly_file) as writer:
164
-
165
- df_output1.to_excel(writer,sheet_name='D31',index=False)
166
-
167
- df_output2.to_excel(writer,sheet_name='D32',index=False)
168
-
169
- ```