简体   繁体   English

将Python数据框中的一列转换为列表

[英]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 期望的:341321432、132184900、173840143、1432473928

Below is my Python code: 下面是我的Python代码:

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'

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM