Home > Software engineering >  Conversion of a pandas series to a list
Conversion of a pandas series to a list

Time:03-23

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

CodePudding user response:

please try this:

ls = list(MyCSV[column_name].values)

add the column_nameaccording to requirement

CodePudding user response:

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() 
  • Related