[LABI] tema04 csv and json examples added
This commit is contained in:
parent
8d0e433173
commit
2b621e2400
|
@ -0,0 +1,12 @@
|
|||
id,time,timestamp,value
|
||||
1,15/03/2014 18:07:24,1394903244.0,2.3
|
||||
1,15/03/2014 18:08:24,1394903304.0,1.8
|
||||
1,15/03/2014 18:09:24,1394903364.0,1.2
|
||||
1,15/03/2014 18:10:24,1394903424.0,1.6
|
||||
1,15/03/2014 18:11:24,1394903484.0,2.1
|
||||
1,15/03/2014 18:12:24,1394903544.0,2.5
|
||||
1,15/03/2014 18:13:24,1394903604.0,2.9
|
||||
1,15/03/2014 18:14:24,1394903664.0,3.3
|
||||
1,15/03/2014 18:15:24,1394903724.0,3.0
|
||||
1,15/03/2014 18:16:24,1394903784.0,2.8
|
||||
1,15/03/2014 18:17:24,1394903844.0,2.4
|
|
|
@ -0,0 +1,26 @@
|
|||
entry,value
|
||||
0,48
|
||||
1,51
|
||||
2,43
|
||||
3,49
|
||||
4,76
|
||||
5,6
|
||||
6,66
|
||||
7,49
|
||||
8,76
|
||||
9,78
|
||||
10,70
|
||||
11,80
|
||||
12,67
|
||||
13,93
|
||||
14,78
|
||||
15,71
|
||||
16,60
|
||||
17,77
|
||||
18,90
|
||||
19,33
|
||||
20,85
|
||||
21,82
|
||||
22,85
|
||||
23,75
|
||||
24,94
|
|
|
@ -0,0 +1,12 @@
|
|||
[
|
||||
{
|
||||
"time": 1394984189,
|
||||
"name": "cpu",
|
||||
"value": 12
|
||||
},
|
||||
{
|
||||
"time": 1394984189,
|
||||
"name": "cpu",
|
||||
"value": 19
|
||||
}
|
||||
]
|
|
@ -0,0 +1,16 @@
|
|||
import csv
|
||||
import random
|
||||
|
||||
|
||||
def main(args=None):
|
||||
with open("../datafiles/example2.csv", "w") as f:
|
||||
writer = csv.DictWriter(f, delimiter=",", fieldnames=["entry", "value"])
|
||||
|
||||
writer.writeheader()
|
||||
|
||||
for i in range(25):
|
||||
writer.writerow({"entry": i, "value": random.randint(0, 100)})
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,13 @@
|
|||
import csv
|
||||
import sys
|
||||
|
||||
|
||||
def main(args=None):
|
||||
with open(args[0], 'r') as f:
|
||||
reader = csv.reader(f, delimiter=(',' if len(args) == 1 else args[1]))
|
||||
for row in reader:
|
||||
print(row)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main(sys.argv[1:])
|
|
@ -0,0 +1,15 @@
|
|||
import json
|
||||
|
||||
|
||||
def main(args=None):
|
||||
data = [
|
||||
{"time": 1394984189, "name": "cpu", "value": 12},
|
||||
{"time": 1394984189, "name": "cpu", "value": 19}
|
||||
]
|
||||
|
||||
print(json.dumps(data, indent=4))
|
||||
json.dump(data, open('../datafiles/example3.json', 'w'), indent=4)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,10 @@
|
|||
import json
|
||||
|
||||
|
||||
def main(args=None):
|
||||
data = json.load(open('../datafiles/example3.json', 'r'))
|
||||
print(json.dumps(data, indent=4))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue