将 Pandas DataFrame 列转换为列表
作者:互联网
方法一:使用 tolist() /to_list()方法将 Dataframe 列转换为列表;
import pandas as pd
df=pd.DataFrame([
['James', '1/1/2014', '1000'],
['Michelina', '2/1/2014', '12000'],
['Marc', '3/1/2014', '36000'],
['Bob', '4/1/2014', '15000'],
['Halena', '4/1/2014', '12000']
], columns=['Name', 'DOB','Salary'])
df['DOB'].tolist() 或df['DOB'].to_list()
Output:
['1/1/2014', '2/1/2014', '3/1/2014', '4/1/2014', '4/1/2014']
方法二:使用 list() 函数将 DataFrame 中的列转换为列表;
list(df['DOB'])
Output:
['1/1/2014', '2/1/2014', '3/1/2014', '4/1/2014', '4/1/2014']
标签:DOB,list,DataFrame,列表,df,2014,Pandas 来源: https://www.cnblogs.com/Jasmine6-Lee/p/16148747.html