python - 如何从excel文件的第一列获取值作为数组?
问题描述
嗨,我想从 excel 文件的第一列中获取值作为数组。
我已经写了这段代码-
import os
import pandas as pd
for file in os.listdir("./python_files"):
if file.endswith(".xlsx"):
df = pd.read_excel(os.path.join("./python_files", file))
print(df.iloc[:,1])
我现在得到的输出
0 172081
1 163314
2 173547
3 284221
4 283170
...
3582 163304
3583 160560
3584 166961
3585 161098
3586 162499
Name: Organization CRD#, Length: 3587, dtype: int64
我想得到什么
172081
163314
173547
284221
283170
...
163304
160560
166961
161098
162499
有人可以帮忙吗?感谢:D
解决方案
您只需要使用 pandas 的tolist函数:
import os
import pandas as pd
for file in os.listdir("./python_files"):
if file.endswith(".xlsx"):
df = pd.read_excel(os.path.join("./python_files", file))
print(df.iloc[:,1].tolist())
输出
172081
163314
173547
284221
283170
...
163304
160560
166961
161098
162499
推荐阅读
- c# - 条码字体在其他设备上无法正常工作 CrystalReports C#
- ios - 如何在 UITextview swift 中使用 linkTextAttributes
- vue.js - 基于角色本地存储的侧边栏
- lua - luajit 使用大量内存后运行错误
- database - 如何将两个 oracle 数据库与在两个实例中运行的相同应用程序合并
- python - Jupyter Notebook 中的内部服务器错误
- android - AOSP/Android 7:EGL如何详细利用?
- php - PHP二叉树配对
- ios - What should I do if my dismiss does not work after a QRcode scan?
- java - 如何通过 solrTemplate 获得建议