Pandas数据形状df.shape的实现
作者:山茶花开时。 时间:2021-01-27 07:19:07
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
标签:Pandas,df.shape
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
详解pygame捕获键盘事件的两种方式
2021-02-27 08:51:54
如何将Yolov5的detect.py修改为可以直接调用的函数详解
2021-12-12 22:21:28
![](https://img.aspxhome.com/file/2023/8/102778_0s.jpg)
关于Python常用模块时间模块time
2022-06-19 14:12:08
![](https://img.aspxhome.com/file/2023/5/76015_0s.jpg)
在PyCharm导航区中打开多个Project的关闭方法
2022-08-11 01:39:11
![](https://img.aspxhome.com/file/2023/8/102938_0s.jpg)
Python从csv文件中读取数据及提取数据的方法
2021-01-26 07:12:44
![](https://img.aspxhome.com/file/2023/7/114507_0s.jpg)
pip 20.3 新版本发布!即将抛弃 Python 2.x(推荐)
2022-04-06 05:10:06
![](https://img.aspxhome.com/file/2023/1/127681_0s.png)
一百行python代码将图片转成字符画
2023-05-06 05:49:15
![](https://img.aspxhome.com/file/2023/1/99701_0s.png)
python批量替换文件名中的共同字符实例
2022-07-11 05:22:37
Python遍历zip文件输出名称时出现乱码问题的解决方法
2022-04-04 15:40:20
Python执行Linux系统命令的4种方法
2023-08-10 19:04:50
自适应网页设计(Responsive Web Design)
2012-05-02 10:49:07
Python生成随机MAC地址
2023-04-09 18:05:57
python文件转为exe文件的方法及用法详解
2022-08-18 00:14:17
python tkinter GUI绘制,以及点击更新显示图片代码
2021-07-27 14:11:33
![](https://img.aspxhome.com/file/2023/7/100927_0s.jpg)
在Python的setuptools框架下生成egg的教程
2021-12-06 13:46:33
python合并多个excel的详细过程
2023-10-03 14:39:26
Python中关键字global和nonlocal的区别详解
2023-08-02 16:42:33
![](https://img.aspxhome.com/file/2023/7/60957_0s.png)
Python3利用Dlib19.7实现摄像头人脸识别的方法
2022-08-08 06:41:22
![](https://img.aspxhome.com/file/2023/1/76031_0s.gif)
对PyQt5基本窗口控件 QMainWindow的使用详解
2021-08-27 21:47:22
![](https://img.aspxhome.com/file/2023/8/90468_0s.jpg)
FrontPage XP设计教程5——表单的设计
2008-10-11 12:35:00
![](https://img.aspxhome.com/file/UploadPic/200810/17/2008101712380183s.jpg)