Reputation: 317
I'm looking to convert a pandas series into a normal list. What is the easiest way to do this?
I've tried the following and it continues to give me an error
import pandas as pd
import numpy as np
MyCSV = pd.read_excel("C:\\Users\\Max von Klemperer\\Desktop\\places.xlsx")
list = []
counter = 0
for i in MyCSV["Column_Name"]:
list[counter] = i
counter = counter + 1
Upvotes: 1
Views: 58
Reputation: 36
lst = MyCSV['column_name'].to_list()
returns a list containing the element of the series corresponding to the column named 'column_name'. If MyCSV is already a pandas Series you can use
lst = MyCSV.to_list()
Upvotes: 2
Reputation: 896
please try this:
ls = list(MyCSV[column_name].values)
add the column_name
according to requirement
Upvotes: 2