python - Python Pandas 'head' 属性不起作用
问题描述
我正在使用 python 和 pandas 编写一个快速脚本来处理一些数据,但是,我正在尝试打印,'head'
但是当我这样做时出现错误。任何想法可能是什么问题?
AttributeError: 'collections.OrderedDict' object has no attribute 'head'
import pandas as pd
my_file_location = "whatever.xlsx"
dfs = pd.read_excel(my_file_location, sheet_name=None)
print(dfs.head())
解决方案
您正在加载一个带有多个工作表的工作簿,并且您传递sheet_name = None
给pd.read_excel()
which 告诉它加载工作簿中的所有工作表并将它们作为字典返回。从字典中选择一张工作表,或将工作表的名称传递给pd.read_excel()
.
例如,要显示所有工作表:
import pandas as pd
my_file_location = "whatever.xlsx"
dfs = pd.read_excel(my_file_location, sheet_name=None)
for n,d in dfs.items():
print('Sheet Name:{}'.format(n))
print(d.head())
或选择名为“somename”的工作表:
import pandas as pd
my_file_location = "whatever.xlsx"
dfs = pd.read_excel(my_file_location, sheet_name='somename')
print(d.head())
推荐阅读
- javascript - 如何将基本身份验证应用于 Javascript 中的 Google Maps API getTileUrl 请求?
- esp32 - 将 I2C HDC1080 温度传感器添加到 esp32cam
- python - ProcessPoolExecutor 因大量任务而死锁
- prometheus - Grafana 看不到来自 Kong Prometheus 插件的数据源
- javascript - 为什么会出现这个错误(“因为这个错误发生在我们跳过当前套件中剩余的测试之前的所有钩子中:”)?
- unix - 用文件集中的当前时间戳替换旧时间戳
- shell - Shell 变量不是通过脚本中的导出创建的
- amazon-cloudwatchlogs - Cloudwatch 记录洞察力在 concat 输出上合并
- python - 检索上传到 GridFS (mongodb) 的 csv
- c - 8的乘法表中出现的数字总和。我的代码有什么问题?理想的输出是 440,我得到 33204