The so-called CSV (Comma Separated Values) format is the most common import and export format for spreadsheets and databases. There were various formats of CSV until its standardization. The lack of a well-defined standard means that subtle differences often exist in the data produced and consumed by different applications. These differences can make it annoying to process CSV files from multiple sources. For that purpose, we will use Python’s
csv library to read and write tabular data in CSV format.
For link to the CSV file used in the code click here.
Code #1: We will use
csv.DictReader() function to import the data file into the Python’s enviornment.
As we can see the data is stored as a list of ordered dictionary. Let’s perform some operations on the data for better understanding.
As we can see in the output, we have 5 unique values of cylinders in our dataset.
Code #3: Now let’s find out the value of average mpg for each value of cylinders.
As we can see in the output, the program has successfully returned a list of tuples containing the average mpg for each unique cylinder type in our dataset.
- Python program to read CSV without CSV module
- Python | Read csv using pandas.read_csv()
- How to read a CSV file to a Dataframe with custom delimiter in Pandas?
- Convert CSV to Excel using Pandas in Python
- How to skip rows while reading csv file using Pandas?
- Pandas - DataFrame to CSV file using tab separator
- Convert Text File to CSV using Python Pandas
- Load CSV data into List and Dictionary using Python
- Different ways to import csv file in Pandas
- Saving a Pandas Dataframe as a CSV
- How to export Pandas DataFrame to a CSV file?
- Export Pandas dataframe to a CSV file
- Writing data from a Python List to CSV row-wise
- Read SQL database table into a Pandas DataFrame using SQLAlchemy
- Writing a CSV file in Java using OpenCSV
- Mapping CSV to JavaBeans Using OpenCSV
- Mapping Java Beans to CSV Using OpenCSV
- Create a GUI to convert CSV file into excel file using Python
- Convert CSV to JSON using Python
- Creating a dataframe using CSV files
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.