简体   繁体   中英

How to show both the random data and the descriptive stats of the dataset in one cell? (Jupyter notebook, pandas)

虹膜

Hi, can someone please help me with this? I want to show the randomly sampled observations and the descriptive statistics together in one cell. However, as a beginner, I can only show one of them.

Here is my code:

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

Thank you for your time and attention!

It will be displayed vertically, which is possible with display() . If you want to make it horizontal, please refer to this answer .

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

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM