python - 如何在一个单元格中同时显示随机数据和数据集的描述性统计数据?(Jupyter 笔记本,熊猫)
问题描述
嗨,有人可以帮我解决这个问题吗?我想在一个单元格中同时显示随机抽样的观察结果和描述性统计数据。但是,作为初学者,我只能展示其中一个。
这是我的代码:
import pandas as pd
iris = pd.read_csv('iris.csv') # Import the csv data
iris = iris.drop('Id', axis = 1) # Delete the 'Id' column
random = iris.sample(10) # Use the sample method to get 10 random samples
random # Show the 10 random samples
random.describe() # Get the descriptive stats
感谢您的时间和关注!
解决方案
它将垂直显示,这可以通过display()
. 如果你想让它水平,请参考这个答案。
display(random, random.describe())
sepal_length sepal_width petal_length petal_width species
141 6.9 3.1 5.1 2.3 virginica
60 5.0 2.0 3.5 1.0 versicolor
65 6.7 3.1 4.4 1.4 versicolor
57 4.9 2.4 3.3 1.0 versicolor
14 5.8 4.0 1.2 0.2 setosa
58 6.6 2.9 4.6 1.3 versicolor
79 5.7 2.6 3.5 1.0 versicolor
102 7.1 3.0 5.9 2.1 virginica
82 5.8 2.7 3.9 1.2 versicolor
15 5.7 4.4 1.5 0.4 setosa
sepal_length sepal_width petal_length petal_width
count 10.000000 10.000000 10.00000 10.000000
mean 6.020000 3.020000 3.69000 1.190000
std 0.769993 0.714609 1.47079 0.652261
min 4.900000 2.000000 1.20000 0.200000
25% 5.700000 2.625000 3.35000 1.000000
50% 5.800000 2.950000 3.70000 1.100000
75% 6.675000 3.100000 4.55000 1.375000
max 7.100000 4.400000 5.90000 2.300000
推荐阅读
- apache-spark - Spark - Yarn 客户端模式下应用程序主控的执行器数量
- mysql - Knex SQL 查询不返回任何内容,MySQL Workbench 返回正确的数据
- f# - 在哪里下载 Paket.fsx
- python - 预期 LP_c_float 实例而不是 glVertex3fv 中的元组
- c# - 如何使用 NodaTime 对 Culture 的 ShortDatePattern 进行字符串格式化?
- node.js - Twilio:如何使用 API 调用启动流程
- python-3.x - 使用 python 3 写入功能时添加的额外字符
- java - 处理程序调度失败;嵌套异常是 java.lang.NoClassDefFoundError: org/rundeck/plugin/scm/git/GitImportPlugin$_getStatusInternal_closure2
- java - 如何检查增强的 for 循环中没有匹配?
- php - 来自 $_POST 数组的 WP update_option()