How to convert records from csv to a list in Python

+1 vote
I have a csv file with 1000 records. I need to add these records to a list in python? is this possible? If yes how to do it?
Jun 25, 2019 in Python by Neel
• 3,020 points
9,851 views

1 answer to this question.

+1 vote

If you are using Python 3.x then the following these steps :-

  • 1. Import csv module.
  • 2. Open the file 
  • 3. Read the file.
  • 4. Convert it into list
  • 5.Print the list
import csv
with open('records.csv', 'r') as f:
  file = csv.reader(f)
  my_list = list(file)
print(my_list)

Hope this is helpful!

To know more join Master in Python programming course today.

Thanks!

answered Jun 25, 2019 by Arvind
• 3,050 points

edited Jun 26, 2019 by Kalgi

Related Questions In Python

0 votes
1 answer

How can I convert a list of dictionaries from a CSV into a JSON object in Python?

You could try using the AST module. ...READ MORE

answered Apr 17, 2018 in Python by anonymous
3,458 views
0 votes
1 answer

How to create LIST from CSV file in Python?

You can use the pandas library for this which ...READ MORE

answered Jul 15, 2019 in Python by Karan
7,111 views
–1 vote
2 answers
0 votes
1 answer
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 get a list of built in modules in Python?

simply open the python shell and type ...READ MORE

answered Aug 1, 2019 in Python by Arvind
• 3,050 points
1,386 views
+1 vote
1 answer

How to install a module in Python 3.6 ?

If you are using Ubuntu then the ...READ MORE

answered Jun 25, 2019 in Python by Arvind
• 3,050 points
1,216 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