網站首頁 編程語言 正文
pandas: shape()獲取Dataframe的行數和列數
返回列數:
df.shape[1]
返回行數:
df.shape[0] 或者:len(df)
返回形狀,即幾行幾列的數組
dataframe.shape()
執行df.shape會返回一個元組,該元組的第一個元素代表行數,第二個元素代表列數,這就是這個數據的基本形狀,也是數據的大小
import pandas as pd
df = pd.DataFrame([['liver','E',89,21,24,64],
['Arry','C',36,37,37,57],
['Ack','A',57,60,18,84],
['Eorge','C',93,96,71,78],
['Oah','D',65,49,61,86]
],
columns = ['name','team','Q1','Q2','Q3','Q4'])
df.shape
# (5, 6)
# 共5行6列(索引不算)
df.shape[0] # 5
df.shape[1] # 6
# Series只有一個值
s = pd.Series(['One','Two','Three'])
s.shape # (3,)
s.shape[0] # 3
結果展示
df
s
原文鏈接:https://blog.csdn.net/Hudas/article/details/122861030
相關推薦
- 2023-01-03 C++?Boost?MetaStateMachine定義狀態機超詳細講解_C 語言
- 2023-02-09 Python如何提取html中文本到txt_python
- 2022-09-25 git問題:“ unable to auto-detect email address”或 “***
- 2022-07-04 Python迭代器的實現原理_python
- 2022-11-07 PostgreSQL長事務概念解析_PostgreSQL
- 2022-04-12 Trailing spaces not allowed no-trailing-spaces
- 2022-04-25 老生常談C語言中指針的使用_C 語言
- 2022-12-01 C語言數據在內存中的存儲流程深入分析_C 語言
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支