read_csv example
This commit is contained in:
parent
a9fe445fa9
commit
ddacee5bcd
2 changed files with 27 additions and 0 deletions
4
python-temel/people.csv
Normal file
4
python-temel/people.csv
Normal file
|
@ -0,0 +1,4 @@
|
|||
isim,no,doğum yeri,oran
|
||||
ali,123,eskişehir,4.2
|
||||
mehmet,256,eskişehir,5.8
|
||||
sacit,452,urfa,7.2
|
|
23
python-temel/read_csv.py
Normal file
23
python-temel/read_csv.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
def read_csv(path, converters=None, header=False):
|
||||
with open(path) as f:
|
||||
if header:
|
||||
h = f.readline()[:-1].split(',')
|
||||
l = []
|
||||
for line in f:
|
||||
a = line[:-1].split(',')
|
||||
if a[0] == '':
|
||||
continue
|
||||
if converters:
|
||||
for key, value in converters.items():
|
||||
a[key] = value(a[key])
|
||||
l.append(a)
|
||||
|
||||
if header:
|
||||
return l, h
|
||||
|
||||
return l
|
||||
|
||||
l, h = read_csv('people.csv', None, True)
|
||||
|
||||
print(l)
|
||||
print(h)
|
Loading…
Reference in a new issue