Asked 30+ days ago
23 Mar 2017
Views 217
Phpworker

Phpworker posted

how to parse csv in PYTHON ?


csv content like this

b'Date,Open,High,Low,Close,Volume,Adj Close\n2017-02-13,18.75,19.10,17.90,18.05,21563900,18.05\n2017-02-10,17.30,17.65,17.05,17.20,7616200,17.20\n


trying to parse csv in Python ?

to read file in Python

fp=open('suzlon.csv')
d=fp.read()


than how can i explode string with new line and comma . is there explode like PHP do in Python ?
ravi

ravi
answered Jan 23 '18 20:17


fp=open('suzlon.csv')
d=fp.read()
print(d)
j=d.split("\\n")
for l in j:
    p=l.split(",")
    print(p)


use split function to split with "\\n" new line and than with comma in Python

last output will be array
Edit Answer
Share

answered Jan 23 '18 20:17

there is no explode function in Python as PHP do , but you can use Split

use splitline to split line in Python
Edit Answer
Share
Mitul Dabhi

Mitul Dabhi
answered Jan 23 '18 20:17

Import CSV module for Python
it a fast CSV reading module for Python
http://www.object-craft.com.au/projects/csv/


import csv
filename = 'suzlon.csv'
csv_file = csv.DictReader(open(filename, 'rb'), delimiter=',', quotechar='"')
Edit Answer
Share
Post Answer