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,010 points
2,116 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)
answered Jun 25, 2019 by Arvind
• 2,980 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
1,957 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
3,296 views
0 votes
2 answers
0 votes
1 answer
+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, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,445 views
0 votes
0 answers
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
• 2,980 points
291 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
• 2,980 points
290 views