How do I convert Pandas object to a list in python3

K A

Basically I need to convert a column I got a from a csv using pandas and put it into a list. It's currently a pandas object and I tried doing list(pandaObject) but that doesn't work. Does anybody have any ideas?

df = pandas.read_csv(csv_file)
years=df[['1987']]  #Gets a a column

###Now I need something to convert years to a list###
amanb

years = df[['1987']] returns a dataframe with only that column. Instead, you should first get a Series out of the column and then convert to a list:

years = df['1987'] #return a Series
years_list = years.tolist() #coverts Series to list

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do i convert a json array object of an object into a java 8 optional list of that object

How do I convert a list into a string with spaces in Python?

How do I convert a Python list into a C array by using ctypes?

In Python, how do I convert all of the items in a list to floats?

How do I convert a list of ascii values to a string in python?

How do I convert an object array to an object list

How do I convert an integer to a list of bits in Python

How do I convert multiple lists inside a list using Python?

How do I convert Pandas DateTime Quarter object into string

how do I convert an object to an array list in JS

How do I convert a list in a .txt file to a list in Processing (python)?

How do i convert python list into pandas dataframe with predefined columns

How do i convert List into datetime.date object?

how do i convert my supervisord configuration from python2 to python3?

How do I convert a list of lists to a python dictionary of the following format?

How do i convert "[object Object]" to a number

How do I convert a python list to simple YAML?

How do I convert List<List<Object>> to a multi-dimensional array?

How do I convert csv string to list in pandas?

How do I convert a list to dictionary with specific format in python?

How do I convert a list of ASCII "Bytes" in Python into Hex Bytes

How do I convert list into dictionary in Python?

Error 'int' object is not subscriptable, How do i convert it to list?

How do I convert a flat list to a list of lists based on value of the elements in python3?

How do I convert a list of integers into an actual list in python

in python how do i convert a list of strings to pandas data frame

How do I convert a list into a dictionary grouped by object name?

How can I convert list of string to pandas DataFrame in Python

How do I convert a bytes object to a string in python?