This repository was archived by the owner on Jan 19, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataCleaner.py
More file actions
164 lines (155 loc) · 5.2 KB
/
DataCleaner.py
File metadata and controls
164 lines (155 loc) · 5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import pandas as pd
# from pandas import ExcelWriter
# from pandas import ExcelFile
raw_files = [
{
'file_name': 'Type1 Data.xlsx',
'sheet_columns': [
{
'sheet_name': 'Type1 March_18',
'cols': 'A,B,D,E,H,IN,IO,IR,IW,IX'
},
{
'sheet_name': 'Type1 April_18',
'cols': 'A,B,D,E,H,IU,IV,IR,IW,IX'
},
{
'sheet_name': 'Type1 May_18',
'cols': 'A,B,D,E,H,IN,IO,IR,IW,IX'
},
{
'sheet_name': 'Type1 June_18',
'cols': 'A,B,D,E,H,IU,IV,IY,IW,IX'
},
{
'sheet_name': 'Type1 July_18',
'cols': 'A,B,D,E,H,IN,IO,IR,IW,IX'
},
{
'sheet_name': 'Type1 Aug_18',
'cols': 'A,B,Q,R,U,JA,JB,JE,JJ,JK'
},
{
'sheet_name': 'Type1 Sep_18',
'cols': 'A,B,Q,R,U,JA,JB,JE,JJ,JK'
},
{
'sheet_name': 'Type1 Nov_18',
'cols': 'A,B,D,E,H,IN,IO,IR,IW,IX'
},
]
},
{
'file_name': 'Type2 Data.xlsx',
'sheet_columns': [
{
'sheet_name': 'Type 2 March_18',
'cols': 'A,B,D,E,H,JA,JB,JE,JI,JK'
},
{
'sheet_name': 'Type 2 April_18',
'cols': 'A,B,D,E,H,JH,JI,JE,JJ,JK'
},
{
'sheet_name': 'Type 2 May_18',
'cols': 'A,B,D,E,H,JA,JB,JE,JJ,JK'
},
{
'sheet_name': 'Type 2 June_18',
'cols': 'A,B,D,E,H,JH,JI,JL,JJ,JK'
},
{
'sheet_name': 'Type 2 July_18',
'cols': 'A,B,D,E,H,JA,JB,JE,JJ,JK'
},
{
'sheet_name': 'Type 2 August_18',
'cols': 'A,B,D,E,H,JA,JB,JE,JJ,JK'
},
{
'sheet_name': 'Type 2 September_18',
'cols': 'A,B,D,E,H,JA,JB,JE,JJ,JK'
},
{
'sheet_name': 'Type 2 November_18',
'cols': 'A,B,D,E,H,JA,JB,JE,JJ,JK'
},
]
},
{
'file_name': 'Type 4 Data.xlsx',
'sheet_columns': [
{
'sheet_name': 'Type 4 March_18',
'cols': 'B,C,GR,GS,GV,JI,JJ,JM,JK,JL'
},
{
'sheet_name': 'Type 4 April_18',
'cols': 'A,B,GQ,GR,GU,JA,JI,JL,JJ,JK'
},
{
'sheet_name': 'Type 4 May_18',
'cols': 'A,B,GQ,GR,GU,JH,JI,JL,JJ,JK'
},
{
'sheet_name': 'Type 4 June_18',
'cols': 'A,B,GQ,GR,GU,JA,JB,JE,JJ,JK'
},
{
'sheet_name': 'Type 4 July_18',
'cols': 'A,B,GQ,GR,GU,JH,JI,JL,JJ,JK'
},
{
'sheet_name': 'Type 4 August_18',
'cols': 'A,B,GQ,GR,GU,JA,JB,JL,JJ,JK'
},
{
'sheet_name': 'Type 4 September_18',
'cols': 'A,B,GQ,GR,GU,JH,JI,JL,JJ,JK'
},
{
'sheet_name': 'Type 4 December_18',
'cols': 'A,B,GQ,GR,GU,JH,JI,JL,JJ,JK'
},
]
}
]
my_columns = ['Date', 'Time', 'SolIrr', 'DaySumIrr', 'TmpMod',
'TmpAmb', 'Wind', 'Pac', 'Pdc', 'DaySum']
# Empty dataframe to contain all Readings
# master_readings = pd.DataFrame()
type_readings = pd.DataFrame()
for file in raw_files:
for sheet in file['sheet_columns']:
df = pd.read_excel(file['file_name'],
sheet_name=sheet['sheet_name'],
header=1,
usecols=sheet['cols'])
# Clean-up column names
df.columns = df.columns.str.replace('Pdc1', 'Pdc')
df.columns = df.columns.str.replace('.1', '')
df.columns = df.columns.str.replace('#', '')
df.columns = df.columns.str.replace('5', '')
print("Excel Sheet Columns: {} - {}".format(file['file_name'], sheet['sheet_name']))
print(df.head())
# re-order columns to be the same everywhere
df = df[my_columns]
print(df.head())
if type_readings.empty:
#master_readings = df.copy(deep=True)
type_readings = df.copy(deep=True)
print('First Run !!')
else:
#master_readings = master_readings.append(df, ignore_index=True, sort=True)
type_readings = type_readings.append(df, ignore_index=True, sort=True)
print('Global Readings: {}'.format(type_readings.shape))
print(type_readings.tail())
# Save Readings in one file
type_readings.to_csv(path_or_buf='{}_flattened.csv'.format(file['file_name']), index=False)
print("Excel File Columns: {}".format(file['file_name']))
print(type_readings.head())
# Clear readings for this type
type_readings = type_readings.iloc[0:0]
#master_readings.to_csv(path_or_buf='flattened_data.csv', index=False)
#print("Flat data Columns")
#print(type_readings.head())