PineNuts0
PineNuts0

Reputation: 5234

Convert One Column in Python Dataframe to List

I have a pandas dataframe consisting of only one column of data. I want to convert the column of data into a list. The column has float datatype.

For example:

ColA
341321432
132184900
173840143
1432473928

Desired: 341321432, 132184900, 173840143, 1432473928

Below is my Python code:

df_gearME = pd.read_excel('Gear M&Es.xlsx')
df_gearME['ColA'].to_list()

But the error I get is as follows:

AttributeError: 'Series' object has no attribute 'to_list'

Upvotes: 2

Views: 27102

Answers (1)

Mike Müller
Mike Müller

Reputation: 85442

Just do:

>>> list(df_gearME.ColA)
[341321432, 132184900, 173840143, 1432473928]

Or print it for horizontal output:

>>> print(list(f_gearME.ColA))
[341321432, 132184900, 173840143, 1432473928]

Upvotes: 8

Related Questions