teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

重複

2021/09/09 03:48

投稿

F91_
F91_

スコア16

answer CHANGED
@@ -1,85 +1,1 @@
1
- ```python
2
- import pandas as pd
3
- from openpyxl import Workbook
4
- import glob
5
-
6
- t=input('更新したい月を入力してくださ')
1
+ 重複てしまいましが、削除が出来なので残ってまっています。
7
- file_list1=glob.glob('//192.168.3.141/pi/mydata'+t+'*')
8
- file_list2=glob.glob('//192.168.3.140/pi/mydata'+t+'*')
9
- file_list3=glob.glob('//192.168.3.139/pi/mydata'+t+'*')
10
- file_list4=glob.glob('//192.168.3.135/pi/mydata'+t+'*')
11
- file_list5=glob.glob('//192.168.3.132/pi/mydata'+t+'*')
12
- file_list6=glob.glob('//192.168.3.131/pi/mydata'+t+'*')
13
- file_list7=glob.glob('//192.168.3.134/pi/mydata'+t+'*')
14
-
15
- rcd1={'日付' : [], '稼働時間(分)': [], '無人稼働時間(分)': [], '停止時間(分)': [],'トータル時間(分)': [],'稼働率(%)': []}
16
-
17
- for file1 in file_list1:
18
-
19
- a1=pd.read_csv(file1)
20
- d1=(file1[25:33])
21
- x1=a1.iloc[:,0].count()
22
- y1=a1.iloc[:,1].sum()
23
- z1=a1.iloc[:,2].sum()
24
- u1=x1-y1-z1
25
- w1=round(y1/x1*100,1)
26
- rcd1['日付'].append(d1)
27
- rcd1['稼働時間(分)'].append(y1)
28
- rcd1['無人稼働時間(分)'].append(z1)
29
- rcd1['停止時間(分)'].append(u1)
30
- rcd1['トータル時間(分)'].append(x1)
31
- rcd1['稼働率(%)'].append(w1)
32
-
33
- df1=pd.DataFrame(rcd1)
34
- print(df1)
35
- g1='全機稼働率'
36
-
37
- monthly_file =g1+ f'{t}.xlsx'
38
-
39
-
40
-
41
-
42
-
43
-
44
- rcd2={'日付' : [], '稼働時間(分)': [], '無人稼働時間(分)': [], '停止時間(分)': [],'トータル時間(分)': [],'稼働率(%)': []}
45
-
46
- for file2 in file_list2:
47
-
48
- a2=pd.read_csv(file2)
49
- d2=(file2[25:33])
50
- x2=a2.iloc[:,0].count()
51
- y2=a2.iloc[:,1].sum()
52
- z2=a2.iloc[:,2].sum()
53
- u2=x2-y2-z2
54
- w2=round(y2/x2*100,1)
55
- rcd2['日付'].append(d2)
56
- rcd2['稼働時間(分)'].append(y2)
57
- rcd2['無人稼働時間(分)'].append(z2)
58
- rcd2['停止時間(分)'].append(u2)
59
- rcd2['トータル時間(分)'].append(x2)
60
- rcd2['稼働率(%)'].append(w2)
61
-
62
- df2=pd.DataFrame(rcd2)
63
- print(df2)
64
-
65
- try:
66
- df_m1 = pd.read_excel(monthly_file,dtype={'日付': str})
67
- df_output1 = pd.merge(df_m1, df1,how='outer')
68
- except FileNotFoundError:
69
- df_output1 = df1.copy()
70
- df_output1['コメント'] = None
71
-
72
- try:
73
- df_m2 = pd.read_excel(monthly_file,dtype={'日付': str})
74
- df_output2 = pd.merge(df_m2, df2,how='outer')
75
- except FileNotFoundError:
76
- df_output2 = df2.copy()
77
- df_output2['コメント'] = None
78
-
79
- #df_output1.to_excel('//192.168.3.225/Share\石岡工場/INV推進室\機械導入PJ/IOT/'+monthly_file1,sheet_name='D31',index=False)
80
- #df_output2.to_excel('//192.168.3.225/Share\石岡工場/INV推進室\機械導入PJ/IOT/'+monthly_file1,sheet_name='D32',index=False)
81
-
82
- with pd.ExcelWriter('//192.168.3.225/Share\石岡工場/INV推進室\機械導入PJ/IOT/'+monthly_file) as writer:
83
- df_output1.to_excel(writer,sheet_name='D31',index=False)
84
- df_output2.to_excel(writer,sheet_name='D32',index=False)
85
- ```