-
Notifications
You must be signed in to change notification settings - Fork 2
/
CSV_convert_file.py
47 lines (31 loc) · 1.25 KB
/
CSV_convert_file.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
import os
path_nobody = 'PIR_data/nobody/'
path_somebody = 'PIR_data/somebody/'
path_change_nobody = 'PIR_data/new_csv/nobody'
path_change_somebody = 'PIR_data/new_csv/somebody'
path_current = os.getcwd()
sensor_count = 3
for root, dirs, files in os.walk(path_nobody + str(sensor_count) + '/'):
for fname in files:
os.chdir(path_current)
os.chdir(path_nobody + str(sensor_count) + '/')
with open(fname, 'r') as f:
data = f.read()
data = data.replace(' ', ',')
os.chdir(path_current)
os.chdir(path_change_nobody + '/' + str(sensor_count) + '/')
with open(fname, 'w') as f:
f.write(data)
print('Sensor ' + str(sensor_count) + ' data is converted .. !')
for root, dirs, files in os.walk(path_somebody + str(sensor_count) + '/'):
for fname in files:
os.chdir(path_current)
os.chdir(path_somebody + str(sensor_count) + '/')
with open(fname, 'r') as f:
data = f.read()
data = data.replace(' ', ',')
os.chdir(path_current)
os.chdir(path_change_somebody + '/' + str(sensor_count) + '/')
with open(fname, 'w') as f:
f.write(data)
print('Sensor ' + str(sensor_count) + ' data is converted .. !')