pandas - Pandas:创建包含总行列的新数据框
问题描述
我有以下数据框:df_Discrep_73L_3,共有 601 行我有第二个数据框:df_Discrep_73Y_3,共有 391 行
我想创建一个具有以下内容的数据框:
ID Total Rows
73Y 601
73L 391
我知道使用 df_Discrep_73L_3.shape 来查找行数,但不知道如何将其放入上述数据框中。
解决方案
.shape 方法以 (rows,columns) 形式返回一个元组。您可以分别使用 shape[0] 和 shape[1] 来保存它们。
rows_73L = df_Discrep_73L_3.shape[0]
rows_73Y = df_Discrep_73Y_3.shape[0]
pd.DataFrame({'ID': ["73Y", "73L"], 'Total Rows': [rows_73Y, rows_73L]})
推荐阅读
- jquery - 想减少在 ajax 中用于 3 个表单验证的类似代码的 jQuery
- python - 使用 pybind11 绑定 typedef 类型的正确语法是什么?
- javascript - 一个谷歌地图javascript中多个按钮加载标记的单击功能
- axapta - 我如何知道我需要更改什么 AOT 类来修改取消订单行的行为
- python - 有没有一种简单的方法可以将 grideye(AMG88xx) 连接到 rpi3 并编程以获取像素数据?
- jsf - 将 bean 从一个 JSF 页面传递到另一个页面
- atk4 - Atk4 UI:表格单元格单击时的回调/模态
- authentication - 如何从控制台应用程序使用 OAuth 进行身份验证?
- powershell - 在powershell中单行打印psobject值
- java - 设置背景图像 gef5