python - Pandas Concat - gspread 工作表
问题描述
我正在尝试连接工作表列表。我已经使用client.open_by_url()
.
我努力了:
worksheet_list = spreadsheet.worksheets()
df = pd.concat(worksheet_list, ignore_index=True)
但是得到这个错误:"TypeError: cannot concatenate object of type '<class 'gspread.models.Worksheet'>'; only Series and DataFrame objs are valid"
问题是有人知道如何连接该gspread.models
类型的工作表。
任何帮助都非常感谢提前。谢谢。
解决方案
工作表对象的类型错误concat
。您需要在合并之前将其更改为 pandas DataFrame。
#Iterate to get dataframes.
list_of_dfs = [pd.DataFrame(ws.get_all_records()) for ws in worksheet_list]
# Concat the list of dataframes
df = df.concat(list_of_dfs, ignore_index=True)
推荐阅读
- java - JavaFX 检查窗格上动画形状之间的碰撞 - 多次碰撞
- r - 如何使误差线与 R Plotly 中的数据匹配
- c++ - 在 C++ 中,为什么有些编译器拒绝将只包含一个 double 的对象放入寄存器?
- fortran - Fortran 中的标量值到底是什么,如何相互转换
- exception - DDD,CQRS,EventSourcing 中错误的不连贯事件流中的逻辑异常?
- javascript - Webpack 4 不会在没有 babel-preset-es2015 的情况下创建 CSS 文件
- docker - 在容器名称上使用 glob / 通配符运行 docker 命令
- c# - 如何删除除一个之外的所有控件?
- css - 为什么不 justify-content: 拉伸工作?
- python - 遗传算法学习最适合指数函数