Read CSV

A CSV (Comma Separated Values) file is a file with values seperated by a comma. Its often used to import and export with databases and spreadsheets.

Example CSV data

Country, Capital, Language, Currency
United States, Washington, English, US dollar
Canada, Ottawa, English and French, Canadian dollar
Germany, Berlin, German, Euro

Values are mostly seperated by comma. Sometimes another character is used like a semicolon, the seperation character is called a delimiter.

Read CSV with Pandas

Pandas is a data analysis library. If you work with data a lot, using pandas is way better.
We can read a csv with the lines:

Pandas works with dataframes which hold all data. Thats why we can use the rows like df[‘name’].

Related Course: Data Analysis in Python with Pandas

Read CSV

If you don’t want to use pandas, you can use the csv module to read csv files.
This is as simple as:

We can access individual cells like so:

Next Post

Leave a Reply