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 | Read csv using pandas.read_csv()
- 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
- Indexing and Selecting Data with Pandas
- Working with Missing Data in Pandas
- Python | Pandas Index.data
- Python | Pandas Series.data
- Pandas Built-in Data Visualization | ML
- Python | Data analysis using Pandas
- Clean the string data in the given Pandas Dataframe
- Add a new column in Pandas Data Frame Using a Dictionary
- Construct a DataFrame in Pandas using string data
- Python | Data Comparison and Selection in Pandas
- Analyzing Mobile Data Speeds from TRAI with Pandas
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.