-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsvFile.py
More file actions
65 lines (46 loc) · 1.82 KB
/
Copy pathcsvFile.py
File metadata and controls
65 lines (46 loc) · 1.82 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
from cassandra.cluster import Cluster
import csv
# 1. Import csv library
import pandas as pd
if __name__ == "__main__":
cluster = Cluster(['rio.pdf.com'],port=9042)
session = cluster.connect('system_schema',wait_for_all_pools=True)
session.execute('USE system_schema')
rows = session.execute("SELECT column_name FROM system_schema.columns WHERE keyspace_name = 'fdc_13407_cass' AND table_name = 'treateddata';")
columns = []
for row in rows:
columns.append(row.column_name)
header = ['fdccontextid',
'indicatorid',
'agg_key',
'anomaly_index',
'anomalyindexalarmlevel',
'spcalarmlevel',
'sum_key',
'td_dcqv',
'value'
]
#data = session.execute("SELECT * FROM fdc_13407_cass.treateddata WHERE fdccontextid = 903146;")
data = session.execute("SELECT * FROM fdc_treateddata_cass.treateddata LIMIT 10000;")
# 2. Define a filename and Open the file using open()
data = pd.DataFrame(data, columns=header)
data.to_csv('Treateddata.csv', index=False)
'''
filename = 'Treateddata.csv'
with open(filename, 'w', newline="") as file:
csvwriter = csv.writer(file) # 3. create a csvwriter object
csvwriter.writerow(header) # 4. write the header
csvwriter.writerows(data) # 5. write the rest of the data
rows = []
with open("Treateddata.csv", 'r') as file:
csvreader = csv.reader(file)
header = next(csvreader)
for row in csvreader:
rows.append(row)
#print(header)
#print(rows)
'''
data= pd.read_csv("Treateddata.csv")
print(data.columns)
print(data.indicatorid)
# https://www.analyticsvidhya.com/blog/2021/08/python-tutorial-working-with-csv-file-for-data-science/