MaxVK
MaxVK

Reputation: 317

Conversion of a pandas series to a list

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

Answers (2)

ArtemusCroa
ArtemusCroa

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

prahasanam_boi
prahasanam_boi

Reputation: 896

please try this:

ls = list(MyCSV[column_name].values)

add the column_nameaccording to requirement

Upvotes: 2

Related Questions