-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclean.py
executable file
·69 lines (59 loc) · 1.44 KB
/
clean.py
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
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import style
import csv
import string
from collections import Counter
import collections, re
import random
from random import randint
import pandas as pd
path = input("Enter the File name with .csv extension, default : 'data/clean-in.csv'.")
if path == "":
path = "data/clean-in.csv"
print(path)
with open(path,newline='') as f:
r = csv.reader(f)
data = [line for line in r]
i=0
j=0
arr=[]
for d in data:
j=0
sublist=[]
if i==0:
sublist.append('date')
sublist.append('time')
sublist.append('value')
i+=1
continue
for cell in d:
if j%2==0:
try:
temp=cell.split()
date=temp[0]
sublist.append(date)
time=temp[1]
lastdigit=time.split(';')
time=lastdigit[0]+":00"
sublist.append(time)
last=lastdigit[1]
except:
sublist=[]
continue
else:
try:
cell=cell.split(';')[0]
value=last+'.'+cell
sublist.append(value)
except:
sublist=[]
continue
j+=1
if sublist!=[]:
arr.append(sublist)
i+=1
with open('data/clean-out.csv','w') as f:
w = csv.writer(f)
w.writerow(['date','time','value'])
w.writerows(arr)