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?
- Python | Plotting charts in excel sheet with Data Tools using XlsxWriter module | Set - 1
- Python | Plotting charts in excel sheet with data tools using XlsxWriter module | Set – 2
- Python | Plotting column charts in excel sheet with data tables using XlsxWriter module
- Python | Pandas Series.data
- Python | Pandas Index.data
- Data profiling in Pandas using Python
- Data Manipulattion in Python using Pandas
- Working with Missing Data in Pandas
- Python | Data analysis using Pandas
- Pandas Built-in Data Visualization | ML
- Indexing and Selecting Data with Pandas
- Get the data type of column in Pandas - Python
- Construct a DataFrame in Pandas using string data
- How to Check the Data Type in Pandas DataFrame?
- Clean the string data in the given Pandas Dataframe
- Python | Data Comparison and Selection in Pandas
- Add a new column in Pandas Data Frame Using a Dictionary
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.