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 in Python by Neel
• 1,610 points
29 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 by Arvind
• 1,530 points

edited Jun 26 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
553 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 6 days ago in Python by Karan
10 views
0 votes
1 answer

How to Print a List in Python

ou are using Python 2.x syntax with ...READ MORE

answered Aug 31, 2018 in Python by charlie_brown
• 7,710 points
58 views
0 votes
1 answer

Convert string list of dict from csv into JSON object in python

You can use the ast module Ex: import ast s = """[{'10': ...READ MORE

answered Sep 12, 2018 in Python by Priyaj
• 56,160 points
340 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 133 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 in Python by Arvind
• 1,530 points
37 views
0 votes
1 answer