示例代码1:
import pandas as pd
df = pd.read_excel('./test.xlsx')
print(df)
print("*" * 50)
# 方法一:直接用list数据类型转换
df_lst1 = list(df['num1'])
print(df_lst1)
df_lst2 = list(df.iloc[:, 0])
print(df_lst2)
print("*" * 50)
# 方法二:
df_lst3 = df['num1'].values.tolist()
print(df_lst3)
df_lst4 = df.iloc[:, 0].values.tolist()
print(df_lst4)
运行结果:
num1 num2
0 1 11
1 2 33
2 3 22
3 4 44
4 6 55
5 5 33
**************************************************
[1, 2, 3, 4, 6, 5]
[1, 2, 3, 4, 6, 5]
**************************************************
[1, 2, 3, 4, 6, 5]
[1, 2, 3, 4, 6, 5]
示例代码2:
import pandas as pd
df = pd.read_excel('./test.xlsx')
print(df)
print("*" * 50)
# 方法三:亲测 将values去掉效果也是一样的
df_lst3 = df['num1'].values.tolist()
print(df_lst3)
df_lst4 = df.iloc[:, 0].tolist()
print(df_lst4)
运行结果:
num1 num2
0 1 11
1 2 33
2 3 22
3 4 44
4 6 55
5 5 33
**************************************************
[1, 2, 3, 4, 6, 5]
[1, 2, 3, 4, 6, 5]