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 in Python by Arvind
• 2,960 points
38 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 by Neel
• 3,010 points

Related Questions In Python

0 votes
1 answer
+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
5,376 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
136 views
0 votes
1 answer

How to Parse values from a JSON file?

import json from pprint import pprint with open('data.json') as ...READ MORE

answered Oct 15, 2018 in Python by Priyaj
• 56,900 points
57 views
+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 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 277 views
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 in Python by Neel
• 3,010 points
446 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 in Python by Neel
• 3,010 points
36 views