In this article, we are going to see how to read CSV files into a list of lists in Python.
In this example, we are reading a CSV file and converting the string into the list.
[['JAN', 34, 360, 417], ['FEB', 31, 342, 391], ['MAR', 36, 406, 419], ['APR', 34, 396, 461],
['MAY', 36, 420, 472], ['JUN', 43, 472, 535], ['JUL', 49, 548, 622], ['AUG', 50, 559, 606],
['SEP', 40, 463, 508], ['OCT', 35, 407, 461], ['NOV', 31, 362, 390], ['DEC', 33, 405, 432]]
In this example, we are reading a CSV file and iterating over lines in the given CSV.
You can use the pandas library for this which has an inbuilt method to convert values to a list. Pandas.values property is used to get a numpy.array and then use the tolist() function to convert that array to list.