 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Extract csv file specific columns to list in Python
To extract csv file for specific columns to list in Python, we can use Pandas read_csv() method.
Steps
- Make a list of columns that have to be extracted. 
- Use read_csv() method to extract the csv file into data frame. 
- Print the exracted data. 
- Plot the data frame using plot() method. 
- To display the figure, use show() method. 
Example
import pandas as pd from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True columns = ["Name", "Marks"] df = pd.read_csv("input.csv", usecols=columns) print("Contents in csv file:\n", df) plt.plot(df.Name, df.Marks) plt.show() The csv file contains the following data −
| Name | Marks | 
|---|---|
| Arun | 98 | 
| Shyam | 75 | 
| Govind | 54 | 
| Javed | 92 | 
| Raju | 87 | 
Output
When we execute the code, it will extract the data from the csv file and show the following plot −

Advertisements
 