Posted on 16 Dec 2018 05:12:33 (8 months ago)
Note: I am using Python3 in this case if you are from Python2 then you have to manipulate below code or may be same. Try and give feedback.
CSV files are common file format for tabular data. We can read CSV file just like other text files. So first I am showing the tradition method then after we will use Python inbuilt module. So lets start with traditional method,
Suppose we have a csv file name 'person.csv' which contains data, for e.g.,
Name,Place,Date Sam,New York,23102015 Juli,Cape Town,12122017 Avinash,New Delhi,09122016 Rio,Tokio,01072015
So as you see the above data is comma seprated data, so below is the tradition code for reading data,
with open('person.csv') as file: file.read()
When you run the above code in python3 console, you will get the giant string which contain all data. Then you have to parse it according to your need. So to overcome these there are inbuilt modules which automatically parse data for you.
Now in next post I will show you the inbuilt method for reading data.