-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15_csv_to_dictionary.py
More file actions
48 lines (40 loc) · 1.14 KB
/
15_csv_to_dictionary.py
File metadata and controls
48 lines (40 loc) · 1.14 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
from osgeo import ogr , gdal , gdal_array as gdarr
import numpy as np
import os
import csv
import string
import pandas as pd
dataDirectory =r'X:\Scientific computing\Data'
os. chdir ( dataDirectory )
def read_csv_file ( file_path ):
data = []
file = open ( file_path )
csv_reader = csv. reader ( file )
for row in csv_reader :
data . append (row)
return data
csv_file= read_csv_file('customers.csv')
print(csv_file)
dict = {}
for row in csv_file:
key= row[0]
value= [row[1], row[2]]
dict[key]= value
print(dict)
print(dict.keys())
################################################
a_file = open("sample.csv", "w")
writer = csv.writer(a_file)
for key, value in dict.items():
writer.writerow([key, value])
a_file.close()
#################################################
def store_dict ( dictionary , file_path ):
file = open ( file_path , "w")
for key in dictionary :
file . write ("%s:%i\n" %(key, dictionary[key]))
file.close ()
store_dict (dict, "abhi_abhi.csv")
#####################################################
a= 18.787
print("%.2f"% a)