How to access specific columns from a csv file

0 votes
I have a csv file. I want to access only specific columns from it. Can it be done using csv module? Is there any other way to do it?
Jul 15, 2019 in Python by Arvind
• 3,050 points
12,010 views

1 answer to this question.

0 votes

Instead of using csv module in Python, I would suggest using the Pandas library. Refer the following code 

import pandas as pd
df1 = pd.read_csv(csv file) # read csv file and store it in a dataframe

Suppose if you want to extract columns A,B and C from your csv file then use the code in the following line

my_columns = df1[["A","B","C" ]]

print(my_columns) #this will print columns A,B,C
answered Jul 15, 2019 by Neel
• 3,020 points

Related Questions In Python

–1 vote
2 answers
0 votes
1 answer

How to list a column of float values from csv file without importing (Python)

Using the default CSV module Demo: import csv with open(filename, "r") ...READ MORE

answered Sep 16, 2020 in Python by Rajiv
• 8,870 points
8,938 views
+1 vote
4 answers

How to write nested dictionaries to a CSV file

Using DictWriter there is no need in ...READ MORE

answered Oct 18, 2018 in Python by Richard William
27,738 views
0 votes
1 answer

How can I write nested dictionaries to a csv file?

You can use the pandas library to ...READ MORE

answered Apr 17, 2018 in Python by anonymous
1,180 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
0 votes
1 answer

How to write a python script for downloading a video from YouTube and saving it to a directory?

First download pytube using the following code  pip ...READ MORE

answered Sep 4, 2019 in Python by Neel
• 3,020 points
2,681 views
0 votes
1 answer

How to check if a given string matches a particular pattern in Python?

You can use re module of python ...READ MORE

answered Jul 3, 2019 in Python by Neel
• 3,020 points
1,201 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP