Before any kind of data processing or usage, we need to know what we are dealing with.
Useful information includes:
The size of the dataset.
The data types and names of the columns.
How values are distributed in each column.
Whether missing values are present, in what measure and where.
Which features are discrete/categorical, and how many categories there are.
Whether columns are strongly correlated with each other.
Loading the data
import pandas as pd# Load the Adult Census datasetdata = pd.read_csv("../data/adult_census/data.csv")target = pd.read_csv("../data/adult_census/target.csv")
Exploring data with Pandas tools 1/3
Let’s first explore the data using Pandas only.
data.head(5)
age
workclass
fnlwgt
education
education-num
marital-status
occupation
relationship
race
sex
capital-gain
capital-loss
hours-per-week
native-country
0
25
Private
226802
11th
7
Never-married
Machine-op-inspct
Own-child
Black
Male
0
0
40
United-States
1
38
Private
89814
HS-grad
9
Married-civ-spouse
Farming-fishing
Husband
White
Male
0
0
50
United-States
2
28
Local-gov
336951
Assoc-acdm
12
Married-civ-spouse
Protective-serv
Husband
White
Male
0
0
40
United-States
3
44
Private
160323
Some-college
10
Married-civ-spouse
Machine-op-inspct
Husband
Black
Male
7688
0
40
United-States
4
18
NaN
103497
Some-college
10
Never-married
NaN
Own-child
White
Female
0
0
30
United-States
Exploring data with Pandas tools 2/3
If we want to have a simpler view of the datatypes in the dataframe, we must use data.info():
The TableReport shows all the columns in the dataset, and allows to select and copy the content of the cells shown in the preview.
As this is a preview, only the first and last few rows are displayed.
The Stats tab
The Stats tab includes information about each column:
full name
detected dtype (no parsing!)
presence of nulls
cardinality (number of unique values)
additional statistics for numerical features
The Distributions tab
A histogram is drawn for each column to show the distribution of values in that column.
Most frequent values are also displayed
The Associations tab
Cramer’s V and Pearson’s correlation coefficient are measured for all pairs of columns.
Associations show whether there are strong correlations between columns, and columns that may be redundant.
Outlier detection
The TableReport detects outliers using a simple interquartile test, marking as outliers all values that are beyond the IQR. This is a simple heuristic, and should not be treated as perfect. If your problem requires reliable outlier detection, you should not rely exclusively on what the TableReport shows.
Filtering the displayed columns
Pre-made column filters are also available, allowing to select columns by dtype or other characteristics. Filters are shared across tabs. It is also possible to define custom filters to select only specific columns:
No columns match the selected filter: . You can change the column filter in the dropdown menu above.
Column
Column name
dtype
Is sorted
Null values
Unique values
Mean
Std
Min
Median
Max
0
age
Int64DType
False
0 (0.0%)
74 (0.2%)
38.6
13.7
17
37
90
1
workclass
ObjectDType
False
2799 (5.7%)
8 (< 0.1%)
2
fnlwgt
Int64DType
False
0 (0.0%)
28523 (58.4%)
1.90e+05
1.06e+05
12,285
178,142
1,490,400
3
education
ObjectDType
False
0 (0.0%)
16 (< 0.1%)
4
education-num
Int64DType
False
0 (0.0%)
16 (< 0.1%)
10.1
2.57
1
10
16
5
marital-status
ObjectDType
False
0 (0.0%)
7 (< 0.1%)
6
occupation
ObjectDType
False
2809 (5.8%)
14 (< 0.1%)
7
relationship
ObjectDType
False
0 (0.0%)
6 (< 0.1%)
8
race
ObjectDType
False
0 (0.0%)
5 (< 0.1%)
9
sex
ObjectDType
False
0 (0.0%)
2 (< 0.1%)
10
capital-gain
Int64DType
False
0 (0.0%)
123 (0.3%)
1.08e+03
7.45e+03
0
0
99,999
11
capital-loss
Int64DType
False
0 (0.0%)
99 (0.2%)
87.5
403.
0
0
4,356
12
hours-per-week
Int64DType
False
0 (0.0%)
96 (0.2%)
40.4
12.4
1
40
99
13
native-country
ObjectDType
False
857 (1.8%)
41 (< 0.1%)
No columns match the selected filter: . You can change the column filter in the dropdown menu above.
To construct a list of column names that you can easily copy-paste
(in the box), select some columns using the checkboxes next
to the column names or the "Select all" button.
The table below shows the strength of association between the most similar columns in the dataframe.
Cramér's V statistic is a number between 0 and 1.
When it is close to 1 the columns are strongly associated — they contain similar information.
In this case, one of them may be redundant and for some models (such as linear models) it might be beneficial to remove it.
Please enable javascript
The skrub table reports need javascript to display correctly. If you are
displaying a report in a Jupyter notebook and you see this message, you may need to
re-execute the cell or to trust the notebook (button on the top right or
"File > Trust notebook").
Skrub selectors can be used for that (more on that later).
Exploring the target variable
Besides dataframes, the TableReport handles series and mono- and bi-dimensional numpy arrays.
TableReport(target)
Click a table cell for more info about its column.
class
0
<=50K
1
<=50K
2
>50K
3
>50K
4
<=50K
48,837
<=50K
48,838
>50K
48,839
<=50K
48,840
<=50K
48,841
>50K
class
ObjectDType
Null values
0 (0.0%)
Unique values
2 (< 0.1%)
Most frequent values
<=50K
>50K
List:
['<=50K', '>50K']
No columns match the selected filter: . You can change the column filter in the dropdown menu above.
Column
Column name
dtype
Is sorted
Null values
Unique values
Mean
Std
Min
Median
Max
0
class
ObjectDType
False
0 (0.0%)
2 (< 0.1%)
No columns match the selected filter: . You can change the column filter in the dropdown menu above.
To construct a list of column names that you can easily copy-paste
(in the box), select some columns using the checkboxes next
to the column names or the "Select all" button.
class
ObjectDType
Null values
0 (0.0%)
Unique values
2 (< 0.1%)
Most frequent values
<=50K
>50K
List:
['<=50K', '>50K']
No columns match the selected filter: . You can change the column filter in the dropdown menu above.
No associations were computed because the dataframe has only one column.
Please enable javascript
The skrub table reports need javascript to display correctly. If you are
displaying a report in a Jupyter notebook and you see this message, you may need to
re-execute the cell or to trust the notebook (button on the top right or
"File > Trust notebook").
Working with big tables
Plot generation and computation of associations are very expensive operations, so it may be beneficial to disable them while working with very big tables.
Use the plot_distributions and compute_associations parameters to do so:
Click a table cell for more info about its column.
age
workclass
fnlwgt
education
education-num
marital-status
occupation
relationship
race
sex
capital-gain
capital-loss
hours-per-week
native-country
0
25
Private
226,802
11th
7
Never-married
Machine-op-inspct
Own-child
Black
Male
0
0
40
United-States
1
38
Private
89,814
HS-grad
9
Married-civ-spouse
Farming-fishing
Husband
White
Male
0
0
50
United-States
2
28
Local-gov
336,951
Assoc-acdm
12
Married-civ-spouse
Protective-serv
Husband
White
Male
0
0
40
United-States
3
44
Private
160,323
Some-college
10
Married-civ-spouse
Machine-op-inspct
Husband
Black
Male
7,688
0
40
United-States
4
18
103,497
Some-college
10
Never-married
Own-child
White
Female
0
0
30
United-States
48,837
27
Private
257,302
Assoc-acdm
12
Married-civ-spouse
Tech-support
Wife
White
Female
0
0
38
United-States
48,838
40
Private
154,374
HS-grad
9
Married-civ-spouse
Machine-op-inspct
Husband
White
Male
0
0
40
United-States
48,839
58
Private
151,910
HS-grad
9
Widowed
Adm-clerical
Unmarried
White
Female
0
0
40
United-States
48,840
22
Private
201,490
HS-grad
9
Never-married
Adm-clerical
Own-child
White
Male
0
0
20
United-States
48,841
52
Self-emp-inc
287,927
HS-grad
9
Married-civ-spouse
Exec-managerial
Wife
White
Female
15,024
0
40
United-States
age
Int64DType
Null values
0 (0.0%)
Unique values
74 (0.2%)
This column has a high cardinality (> 40).
Mean ± Std
38.6 ±
13.7
Median ± IQR
37 ±
20
Min | Max
17 |
90
workclass
ObjectDType
Null values
2,799 (5.7%)
Unique values
8 (< 0.1%)
fnlwgt
Int64DType
Null values
0 (0.0%)
Unique values
28,523 (58.4%)
This column has a high cardinality (> 40).
Mean ± Std
1.90e+05 ±
1.06e+05
Median ± IQR
178,142 ±
120,097
Min | Max
12,285 |
1,490,400
education
ObjectDType
Null values
0 (0.0%)
Unique values
16 (< 0.1%)
education-num
Int64DType
Null values
0 (0.0%)
Unique values
16 (< 0.1%)
Mean ± Std
10.1 ±
2.57
Median ± IQR
10 ±
3
Min | Max
1 |
16
marital-status
ObjectDType
Null values
0 (0.0%)
Unique values
7 (< 0.1%)
occupation
ObjectDType
Null values
2,809 (5.8%)
Unique values
14 (< 0.1%)
relationship
ObjectDType
Null values
0 (0.0%)
Unique values
6 (< 0.1%)
race
ObjectDType
Null values
0 (0.0%)
Unique values
5 (< 0.1%)
sex
ObjectDType
Null values
0 (0.0%)
Unique values
2 (< 0.1%)
capital-gain
Int64DType
Null values
0 (0.0%)
Unique values
123 (0.3%)
This column has a high cardinality (> 40).
Mean ± Std
1.08e+03 ±
7.45e+03
Median ± IQR
0 ±
0
Min | Max
0 |
99,999
capital-loss
Int64DType
Null values
0 (0.0%)
Unique values
99 (0.2%)
This column has a high cardinality (> 40).
Mean ± Std
87.5 ±
403.
Median ± IQR
0 ±
0
Min | Max
0 |
4,356
hours-per-week
Int64DType
Null values
0 (0.0%)
Unique values
96 (0.2%)
This column has a high cardinality (> 40).
Mean ± Std
40.4 ±
12.4
Median ± IQR
40 ±
5
Min | Max
1 |
99
native-country
ObjectDType
Null values
857 (1.8%)
Unique values
41 (< 0.1%)
This column has a high cardinality (> 40).
No columns match the selected filter: . You can change the column filter in the dropdown menu above.
Column
Column name
dtype
Is sorted
Null values
Unique values
Mean
Std
Min
Median
Max
0
age
Int64DType
False
0 (0.0%)
74 (0.2%)
38.6
13.7
17
37
90
1
workclass
ObjectDType
False
2799 (5.7%)
8 (< 0.1%)
2
fnlwgt
Int64DType
False
0 (0.0%)
28523 (58.4%)
1.90e+05
1.06e+05
12,285
178,142
1,490,400
3
education
ObjectDType
False
0 (0.0%)
16 (< 0.1%)
4
education-num
Int64DType
False
0 (0.0%)
16 (< 0.1%)
10.1
2.57
1
10
16
5
marital-status
ObjectDType
False
0 (0.0%)
7 (< 0.1%)
6
occupation
ObjectDType
False
2809 (5.8%)
14 (< 0.1%)
7
relationship
ObjectDType
False
0 (0.0%)
6 (< 0.1%)
8
race
ObjectDType
False
0 (0.0%)
5 (< 0.1%)
9
sex
ObjectDType
False
0 (0.0%)
2 (< 0.1%)
10
capital-gain
Int64DType
False
0 (0.0%)
123 (0.3%)
1.08e+03
7.45e+03
0
0
99,999
11
capital-loss
Int64DType
False
0 (0.0%)
99 (0.2%)
87.5
403.
0
0
4,356
12
hours-per-week
Int64DType
False
0 (0.0%)
96 (0.2%)
40.4
12.4
1
40
99
13
native-country
ObjectDType
False
857 (1.8%)
41 (< 0.1%)
No columns match the selected filter: . You can change the column filter in the dropdown menu above.
To construct a list of column names that you can easily copy-paste
(in the box), select some columns using the checkboxes next
to the column names or the "Select all" button.
Plotting was skipped. This is due to either:
The dataframe exceeding the configured
table_report_plots_threshold
limit (default: 30).
The plot_distributions option being set to False (default: "auto", which applies the configured table_report_plots_threshold).
You can adjust this behavior in several ways:
To force plotting for a single report:
report = TableReport(df, plot_distributions=True)
To change the threshold for the current Python session, use skrub.set_config:
from skrub import set_config
set_config(table_report_plots_threshold=50)
To make the change permanent, use an environment variable:
export SKB_TABLE_REPORT_PLOTS_THRESHOLD=50
No columns match the selected filter: . You can change the column filter in the dropdown menu above.
Computing pairwise associations was skipped. This is due to either:
The dataframe exceeding the configured
table_report_associations_threshold
limit (default: 30).
The compute_associations option being set to False (default: "auto", which applies the configured table_report_associations_threshold).
To change the threshold for the current Python session, use skrub.set_config:
from skrub import set_config
set_config(table_report_associations_threshold=50)
To make the change permanent, use an environment variable:
export SKB_TABLE_REPORT_ASSOCIATIONS_THRESHOLD=50
Please enable javascript
The skrub table reports need javascript to display correctly. If you are
displaying a report in a Jupyter notebook and you see this message, you may need to
re-execute the cell or to trust the notebook (button on the top right or
"File > Trust notebook").
Exporting the TableReport
The TableReport computes many statistics about a given table. Typically, the interactive view is sufficient when developing with a notebook.
It is also possible to export the statistics in various formats to share them, or to use them programmatically.
Exporting the TableReport: HTML
The TableReport can be saved on disk as an HTML.
TableReport(data).write_html("report.html")
Tip
The report can be opened using any internet browser, with no need to run a Jupyter notebok or a python interactive console.
Exporting the TableReport: JSON
It is also possible to export the report in JSON format:
json_str = TableReport(data).json()
Important
If the report is generating distribution plots, the JSON will include them in SVG format. Distributions can be disabled by setting plot_distributions=False.
Exporting the TableReport: Markdown
(in the upcoming release!)
Finally, the report can be exported in summarized form as a Markdown-formatted string:
md_str = TableReport(data).markdown()withopen("report.md", "w") as fp: fp.write(md_str)
Warning
The TableReport does not do any sanitization of the input data, and prints out column names and most frequent values as part of the output. Do not feed the content of the report to an agent if the dataset is large, or if its content is not trusted.
What we have seen in this chapter
Creating and configuring a TableReport for fast, interactive data exploration
Exploring column statistics, value distributions, and associations visually
Detecting nulls, outliers, and highly correlated columns at a glance
Filtering columns by type or characteristics using built-in filters
Adjusting TableReport settings for large datasets to optimize performance
Saving and exporting reports as HTML, JSON, and Markdown files