inspectpd 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- inspectpd/__init__.py +71 -0
- inspectpd/data/starwars.csv +88 -0
- inspectpd/data/tdf.csv +111 -0
- inspectpd/inspect/__init__.py +0 -0
- inspectpd/inspect/inspect_cat.py +56 -0
- inspectpd/inspect/inspect_cor.py +99 -0
- inspectpd/inspect/inspect_imb.py +52 -0
- inspectpd/inspect/inspect_mem.py +54 -0
- inspectpd/inspect/inspect_na.py +46 -0
- inspectpd/inspect/inspect_num.py +57 -0
- inspectpd/inspect/inspect_types.py +51 -0
- inspectpd/inspect_object/__init__.py +0 -0
- inspectpd/inspect_object/inspect_object.py +63 -0
- inspectpd/view/__init__.py +0 -0
- inspectpd/view/utils.py +7 -0
- inspectpd/view/view_cat.py +139 -0
- inspectpd/view/view_cor.py +45 -0
- inspectpd/view/view_imb.py +59 -0
- inspectpd/view/view_mem.py +56 -0
- inspectpd/view/view_na.py +64 -0
- inspectpd/view/view_num.py +25 -0
- inspectpd/view/view_types.py +79 -0
- inspectpd-0.2.0.dist-info/METADATA +125 -0
- inspectpd-0.2.0.dist-info/RECORD +26 -0
- inspectpd-0.2.0.dist-info/WHEEL +4 -0
- inspectpd-0.2.0.dist-info/licenses/LICENSE.txt +21 -0
inspectpd/__init__.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""inspectpd: inspection, comparison and visualisation of pandas data frames.
|
|
2
|
+
|
|
3
|
+
Importing this package monkey-patches a family of ``inspect_*`` methods onto
|
|
4
|
+
pandas objects. Two small example datasets (``starwars`` and ``tdf``) are
|
|
5
|
+
exposed as lazily loaded module attributes.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from functools import cache
|
|
9
|
+
from importlib.resources import files
|
|
10
|
+
|
|
11
|
+
from pandas import read_csv
|
|
12
|
+
from pandas.core.base import PandasObject
|
|
13
|
+
|
|
14
|
+
from .inspect.inspect_cat import inspect_cat
|
|
15
|
+
from .inspect.inspect_cor import inspect_cor
|
|
16
|
+
from .inspect.inspect_imb import inspect_imb
|
|
17
|
+
from .inspect.inspect_mem import inspect_mem
|
|
18
|
+
from .inspect.inspect_na import inspect_na
|
|
19
|
+
from .inspect.inspect_num import inspect_num
|
|
20
|
+
from .inspect.inspect_types import inspect_types
|
|
21
|
+
|
|
22
|
+
__all__ = [
|
|
23
|
+
"inspect_cat",
|
|
24
|
+
"inspect_cor",
|
|
25
|
+
"inspect_imb",
|
|
26
|
+
"inspect_mem",
|
|
27
|
+
"inspect_na",
|
|
28
|
+
"inspect_num",
|
|
29
|
+
"inspect_types",
|
|
30
|
+
"load_dataset",
|
|
31
|
+
"starwars",
|
|
32
|
+
"tdf",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
# monkey-patch the inspect_* functions as methods on pandas objects
|
|
36
|
+
PandasObject.inspect_imb = inspect_imb
|
|
37
|
+
PandasObject.inspect_na = inspect_na
|
|
38
|
+
PandasObject.inspect_types = inspect_types
|
|
39
|
+
PandasObject.inspect_mem = inspect_mem
|
|
40
|
+
PandasObject.inspect_cat = inspect_cat
|
|
41
|
+
PandasObject.inspect_cor = inspect_cor
|
|
42
|
+
PandasObject.inspect_num = inspect_num
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
# read_csv kwargs for each bundled example dataset
|
|
46
|
+
_DATASETS = {
|
|
47
|
+
"starwars": {"index_col": 0},
|
|
48
|
+
"tdf": {},
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@cache
|
|
53
|
+
def load_dataset(name):
|
|
54
|
+
"""Load a bundled example dataset by name (``"starwars"`` or ``"tdf"``)."""
|
|
55
|
+
if name not in _DATASETS:
|
|
56
|
+
valid = ", ".join(sorted(_DATASETS))
|
|
57
|
+
raise ValueError(f"unknown dataset {name!r}; choose from: {valid}")
|
|
58
|
+
resource = files("inspectpd").joinpath("data", f"{name}.csv")
|
|
59
|
+
with resource.open("rb") as handle:
|
|
60
|
+
return read_csv(handle, **_DATASETS[name])
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def __getattr__(name):
|
|
64
|
+
"""Lazily expose example datasets as module attributes (PEP 562)."""
|
|
65
|
+
if name in _DATASETS:
|
|
66
|
+
return load_dataset(name)
|
|
67
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def __dir__():
|
|
71
|
+
return sorted(set(globals()) | set(_DATASETS))
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"","name","height","mass","hair_color","skin_color","eye_color","birth_year","gender","homeworld","species"
|
|
2
|
+
"1","Luke Skywalker",172,77,"blond","fair","blue",19,"male","Tatooine","Human"
|
|
3
|
+
"2","C-3PO",167,75,NA,"gold","yellow",112,NA,"Tatooine","Droid"
|
|
4
|
+
"3","R2-D2",96,32,NA,"white, blue","red",33,NA,"Naboo","Droid"
|
|
5
|
+
"4","Darth Vader",202,136,"none","white","yellow",41.9,"male","Tatooine","Human"
|
|
6
|
+
"5","Leia Organa",150,49,"brown","light","brown",19,"female","Alderaan","Human"
|
|
7
|
+
"6","Owen Lars",178,120,"brown, grey","light","blue",52,"male","Tatooine","Human"
|
|
8
|
+
"7","Beru Whitesun lars",165,75,"brown","light","blue",47,"female","Tatooine","Human"
|
|
9
|
+
"8","R5-D4",97,32,NA,"white, red","red",NA,NA,"Tatooine","Droid"
|
|
10
|
+
"9","Biggs Darklighter",183,84,"black","light","brown",24,"male","Tatooine","Human"
|
|
11
|
+
"10","Obi-Wan Kenobi",182,77,"auburn, white","fair","blue-gray",57,"male","Stewjon","Human"
|
|
12
|
+
"11","Anakin Skywalker",188,84,"blond","fair","blue",41.9,"male","Tatooine","Human"
|
|
13
|
+
"12","Wilhuff Tarkin",180,NA,"auburn, grey","fair","blue",64,"male","Eriadu","Human"
|
|
14
|
+
"13","Chewbacca",228,112,"brown","unknown","blue",200,"male","Kashyyyk","Wookiee"
|
|
15
|
+
"14","Han Solo",180,80,"brown","fair","brown",29,"male","Corellia","Human"
|
|
16
|
+
"15","Greedo",173,74,NA,"green","black",44,"male","Rodia","Rodian"
|
|
17
|
+
"16","Jabba Desilijic Tiure",175,1358,NA,"green-tan, brown","orange",600,"hermaphrodite","Nal Hutta","Hutt"
|
|
18
|
+
"17","Wedge Antilles",170,77,"brown","fair","hazel",21,"male","Corellia","Human"
|
|
19
|
+
"18","Jek Tono Porkins",180,110,"brown","fair","blue",NA,"male","Bestine IV","Human"
|
|
20
|
+
"19","Yoda",66,17,"white","green","brown",896,"male",NA,"Yoda's species"
|
|
21
|
+
"20","Palpatine",170,75,"grey","pale","yellow",82,"male","Naboo","Human"
|
|
22
|
+
"21","Boba Fett",183,78.2,"black","fair","brown",31.5,"male","Kamino","Human"
|
|
23
|
+
"22","IG-88",200,140,"none","metal","red",15,"none",NA,"Droid"
|
|
24
|
+
"23","Bossk",190,113,"none","green","red",53,"male","Trandosha","Trandoshan"
|
|
25
|
+
"24","Lando Calrissian",177,79,"black","dark","brown",31,"male","Socorro","Human"
|
|
26
|
+
"25","Lobot",175,79,"none","light","blue",37,"male","Bespin","Human"
|
|
27
|
+
"26","Ackbar",180,83,"none","brown mottle","orange",41,"male","Mon Cala","Mon Calamari"
|
|
28
|
+
"27","Mon Mothma",150,NA,"auburn","fair","blue",48,"female","Chandrila","Human"
|
|
29
|
+
"28","Arvel Crynyd",NA,NA,"brown","fair","brown",NA,"male",NA,"Human"
|
|
30
|
+
"29","Wicket Systri Warrick",88,20,"brown","brown","brown",8,"male","Endor","Ewok"
|
|
31
|
+
"30","Nien Nunb",160,68,"none","grey","black",NA,"male","Sullust","Sullustan"
|
|
32
|
+
"31","Qui-Gon Jinn",193,89,"brown","fair","blue",92,"male",NA,"Human"
|
|
33
|
+
"32","Nute Gunray",191,90,"none","mottled green","red",NA,"male","Cato Neimoidia","Neimodian"
|
|
34
|
+
"33","Finis Valorum",170,NA,"blond","fair","blue",91,"male","Coruscant","Human"
|
|
35
|
+
"34","Jar Jar Binks",196,66,"none","orange","orange",52,"male","Naboo","Gungan"
|
|
36
|
+
"35","Roos Tarpals",224,82,"none","grey","orange",NA,"male","Naboo","Gungan"
|
|
37
|
+
"36","Rugor Nass",206,NA,"none","green","orange",NA,"male","Naboo","Gungan"
|
|
38
|
+
"37","Ric Olié",183,NA,"brown","fair","blue",NA,"male","Naboo",NA
|
|
39
|
+
"38","Watto",137,NA,"black","blue, grey","yellow",NA,"male","Toydaria","Toydarian"
|
|
40
|
+
"39","Sebulba",112,40,"none","grey, red","orange",NA,"male","Malastare","Dug"
|
|
41
|
+
"40","Quarsh Panaka",183,NA,"black","dark","brown",62,"male","Naboo",NA
|
|
42
|
+
"41","Shmi Skywalker",163,NA,"black","fair","brown",72,"female","Tatooine","Human"
|
|
43
|
+
"42","Darth Maul",175,80,"none","red","yellow",54,"male","Dathomir","Zabrak"
|
|
44
|
+
"43","Bib Fortuna",180,NA,"none","pale","pink",NA,"male","Ryloth","Twi'lek"
|
|
45
|
+
"44","Ayla Secura",178,55,"none","blue","hazel",48,"female","Ryloth","Twi'lek"
|
|
46
|
+
"45","Dud Bolt",94,45,"none","blue, grey","yellow",NA,"male","Vulpter","Vulptereen"
|
|
47
|
+
"46","Gasgano",122,NA,"none","white, blue","black",NA,"male","Troiken","Xexto"
|
|
48
|
+
"47","Ben Quadinaros",163,65,"none","grey, green, yellow","orange",NA,"male","Tund","Toong"
|
|
49
|
+
"48","Mace Windu",188,84,"none","dark","brown",72,"male","Haruun Kal","Human"
|
|
50
|
+
"49","Ki-Adi-Mundi",198,82,"white","pale","yellow",92,"male","Cerea","Cerean"
|
|
51
|
+
"50","Kit Fisto",196,87,"none","green","black",NA,"male","Glee Anselm","Nautolan"
|
|
52
|
+
"51","Eeth Koth",171,NA,"black","brown","brown",NA,"male","Iridonia","Zabrak"
|
|
53
|
+
"52","Adi Gallia",184,50,"none","dark","blue",NA,"female","Coruscant","Tholothian"
|
|
54
|
+
"53","Saesee Tiin",188,NA,"none","pale","orange",NA,"male","Iktotch","Iktotchi"
|
|
55
|
+
"54","Yarael Poof",264,NA,"none","white","yellow",NA,"male","Quermia","Quermian"
|
|
56
|
+
"55","Plo Koon",188,80,"none","orange","black",22,"male","Dorin","Kel Dor"
|
|
57
|
+
"56","Mas Amedda",196,NA,"none","blue","blue",NA,"male","Champala","Chagrian"
|
|
58
|
+
"57","Gregar Typho",185,85,"black","dark","brown",NA,"male","Naboo","Human"
|
|
59
|
+
"58","Cordé",157,NA,"brown","light","brown",NA,"female","Naboo","Human"
|
|
60
|
+
"59","Cliegg Lars",183,NA,"brown","fair","blue",82,"male","Tatooine","Human"
|
|
61
|
+
"60","Poggle the Lesser",183,80,"none","green","yellow",NA,"male","Geonosis","Geonosian"
|
|
62
|
+
"61","Luminara Unduli",170,56.2,"black","yellow","blue",58,"female","Mirial","Mirialan"
|
|
63
|
+
"62","Barriss Offee",166,50,"black","yellow","blue",40,"female","Mirial","Mirialan"
|
|
64
|
+
"63","Dormé",165,NA,"brown","light","brown",NA,"female","Naboo","Human"
|
|
65
|
+
"64","Dooku",193,80,"white","fair","brown",102,"male","Serenno","Human"
|
|
66
|
+
"65","Bail Prestor Organa",191,NA,"black","tan","brown",67,"male","Alderaan","Human"
|
|
67
|
+
"66","Jango Fett",183,79,"black","tan","brown",66,"male","Concord Dawn","Human"
|
|
68
|
+
"67","Zam Wesell",168,55,"blonde","fair, green, yellow","yellow",NA,"female","Zolan","Clawdite"
|
|
69
|
+
"68","Dexter Jettster",198,102,"none","brown","yellow",NA,"male","Ojom","Besalisk"
|
|
70
|
+
"69","Lama Su",229,88,"none","grey","black",NA,"male","Kamino","Kaminoan"
|
|
71
|
+
"70","Taun We",213,NA,"none","grey","black",NA,"female","Kamino","Kaminoan"
|
|
72
|
+
"71","Jocasta Nu",167,NA,"white","fair","blue",NA,"female","Coruscant","Human"
|
|
73
|
+
"72","Ratts Tyerell",79,15,"none","grey, blue","unknown",NA,"male","Aleen Minor","Aleena"
|
|
74
|
+
"73","R4-P17",96,NA,"none","silver, red","red, blue",NA,"female",NA,NA
|
|
75
|
+
"74","Wat Tambor",193,48,"none","green, grey","unknown",NA,"male","Skako","Skakoan"
|
|
76
|
+
"75","San Hill",191,NA,"none","grey","gold",NA,"male","Muunilinst","Muun"
|
|
77
|
+
"76","Shaak Ti",178,57,"none","red, blue, white","black",NA,"female","Shili","Togruta"
|
|
78
|
+
"77","Grievous",216,159,"none","brown, white","green, yellow",NA,"male","Kalee","Kaleesh"
|
|
79
|
+
"78","Tarfful",234,136,"brown","brown","blue",NA,"male","Kashyyyk","Wookiee"
|
|
80
|
+
"79","Raymus Antilles",188,79,"brown","light","brown",NA,"male","Alderaan","Human"
|
|
81
|
+
"80","Sly Moore",178,48,"none","pale","white",NA,"female","Umbara",NA
|
|
82
|
+
"81","Tion Medon",206,80,"none","grey","black",NA,"male","Utapau","Pau'an"
|
|
83
|
+
"82","Finn",NA,NA,"black","dark","dark",NA,"male",NA,"Human"
|
|
84
|
+
"83","Rey",NA,NA,"brown","light","hazel",NA,"female",NA,"Human"
|
|
85
|
+
"84","Poe Dameron",NA,NA,"brown","light","brown",NA,"male",NA,"Human"
|
|
86
|
+
"85","BB8",NA,NA,"none","none","black",NA,"none",NA,"Droid"
|
|
87
|
+
"86","Captain Phasma",NA,NA,"unknown","unknown","unknown",NA,"female",NA,NA
|
|
88
|
+
"87","Padmé Amidala",165,45,"brown","light","brown",46,"female","Naboo","Human"
|
inspectpd/data/tdf.csv
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
edition,start_date,winner_name,winner_team,distance,time_overall,time_margin,stage_wins,stages_led,height,weight,age,born,died,full_name,nickname,birth_town,birth_country,nationality
|
|
2
|
+
1,1903-07-01,Maurice Garin,La Française,2428,94.55388888888889,2.9891666666666667,3,6,1.62,60,32,1871-03-03,1957-02-19,NA,The Little Chimney-sweep,Arvier,Italy, France
|
|
3
|
+
2,1904-07-02,Henri Cornet,Conte,2428,96.09861111111111,2.2705555555555557,1,3,NA,NA,19,1884-08-04,1941-03-18,NA,Le rigolo (The joker),Desvres,France, France
|
|
4
|
+
3,1905-07-09,Louis Trousselier,Peugeot–Wolber,2994,NA,NA,5,10,NA,NA,24,1881-06-29,1939-04-24,NA,Levaloy / Trou-trou,Paris,France, France
|
|
5
|
+
4,1906-07-04,René Pottier,Peugeot–Wolber,4637,NA,NA,5,12,NA,NA,27,1879-06-05,1907-01-25,NA,NA,Moret-sur-Loing,France, France
|
|
6
|
+
5,1907-07-08,Lucien Petit-Breton,Peugeot–Wolber,4488,NA,NA,2,5,NA,NA,24,1882-10-18,1917-12-20,Lucien Georges Mazan,Lucien Petit-Breton,Plessé,France, France
|
|
7
|
+
6,1908-07-13,Lucien Petit-Breton,Peugeot–Wolber,4497,NA,NA,5,13,NA,NA,25,1882-10-18,1917-12-20,Lucien Georges Mazan,Lucien Petit-Breton,Plessé,France, France
|
|
8
|
+
7,1909-07-05,François Faber,Alcyon–Dunlop,4498,NA,NA,6,13,1.78,88,22,1887-01-26,1915-05-09,NA,The giant of colombes,Aulnay-sur-Iton,France, Luxembourg
|
|
9
|
+
8,1910-07-01,Octave Lapize,Alcyon–Dunlop,4734,NA,NA,4,3,NA,NA,22,1887-10-24,1917-07-14,NA,NA,Paris,France, France
|
|
10
|
+
9,1911-07-02,Gustave Garrigou,Alcyon–Dunlop,5343,NA,NA,2,13,NA,NA,26,1884-09-24,1963-01-28,Cyprien Gustave Garrigou,NA,Vabres,France, France
|
|
11
|
+
10,1912-06-30,Odile Defraye,Alcyon–Dunlop,5289,NA,NA,3,13,NA,NA,23,1888-07-14,1965-08-21,NA,NA,Rumbeke,Belgium, Belgium
|
|
12
|
+
11,1913-06-29,Philippe Thys,Peugeot–Wolber,5287,197.9,0.13555555555555554,1,8,NA,NA,23,1889-10-08,1971-01-16,NA,Le basset (The Basset Hound),Anderlecht,Belgium, Belgium
|
|
13
|
+
12,1914-06-28,Philippe Thys,Peugeot–Wolber,5380,200.48,0.016944444444444443,1,15,NA,NA,24,1889-10-08,1971-01-16,NA,Le basset (The Basset Hound),Anderlecht,Belgium, Belgium
|
|
14
|
+
13,1919-06-29,Firmin Lambot,La Sportive,5560,231.12083333333334,1.7149999999999999,1,2,NA,NA,33,1886-03-14,1964-01-19,NA,NA,Florennes,Belgium, Belgium
|
|
15
|
+
14,1920-06-27,Philippe Thys,La Sportive,5503,228.6036111111111,0.9658333333333333,4,14,NA,NA,30,1889-10-08,1971-01-16,NA,Le basset (The Basset Hound),Anderlecht,Belgium, Belgium
|
|
16
|
+
15,1921-06-26,Léon Scieur,La Sportive,5485,221.84055555555557,0.305,2,14,NA,NA,33,1888-03-18,1969-10-07,NA,NA,Florennes,Belgium, Belgium
|
|
17
|
+
16,1922-06-25,Firmin Lambot,Peugeot–Wolber,5375,222.135,0.6947222222222222,0,3,NA,NA,36,1886-03-14,1964-01-19,NA,NA,Florennes,Belgium, Belgium
|
|
18
|
+
17,1923-06-24,Henri Pélissier,Automoto–Hutchinson,5386,222.25833333333333,0.5083333333333333,3,6,NA,NA,34,1889-01-22,1935-05-01,NA,NA,Paris,France, France
|
|
19
|
+
18,1924-06-22,Ottavio Bottecchia,Automoto,5425,226.30583333333334,0.5930555555555556,4,15,NA,NA,29,1894-08-01,1927-06-15,NA,NA,San Martino di Colle Umberto,Italy, Italy
|
|
20
|
+
19,1925-06-21,Ottavio Bottecchia,Automoto–Hutchinson,5440,219.17166666666665,0.915,4,13,NA,NA,30,1894-08-01,1927-06-15,NA,NA,San Martino di Colle Umberto,Italy, Italy
|
|
21
|
+
20,1926-06-20,Lucien Buysse,Automoto–Hutchinson,5745,238.74027777777778,1.3736111111111111,2,8,NA,NA,33,1892-09-11,1980-01-03,NA,NA,Wontergem,Belgium, Belgium
|
|
22
|
+
21,1927-06-19,Nicolas Frantz,Alcyon–Dunlop,5398,198.27833333333334,1.811388888888889,3,14,NA,NA,27,1899-11-04,1985-11-08,NA,NA,Mamer,Luxembourg, Luxembourg
|
|
23
|
+
22,1928-06-17,Nicolas Frantz,Alcyon–Dunlop,5476,192.81611111111113,0.8472222222222222,5,22,NA,NA,28,1899-11-04,1985-11-08,NA,NA,Mamer,Luxembourg, Luxembourg
|
|
24
|
+
23,1929-06-30,Maurice De Waele,Alcyon–Dunlop,5286,186.65416666666667,0.7455555555555555,1,16,NA,NA,32,1896-12-27,1952-02-14,NA,NA,Lovendegem,Belgium, Belgium
|
|
25
|
+
24,1930-07-02,André Leducq,Alcyon–Dunlop,4822,172.20444444444442,0.23722222222222222,2,13,NA,NA,26,1904-02-27,1980-06-18,NA,NA,Saint-Ouen,France, France
|
|
26
|
+
25,1931-06-30,Antonin Magne,France,5091,177.1675,0.20333333333333334,1,16,NA,NA,27,1904-01-15,1983-09-08,NA,NA,Ytrac,France, France
|
|
27
|
+
26,1932-07-06,André Leducq,France,4479,154.19694444444445,0.4066666666666667,6,19,NA,NA,28,1904-02-27,1980-06-18,NA,NA,Saint-Ouen,France, France
|
|
28
|
+
27,1933-06-27,Georges Speicher,France,4395,147.86027777777778,0.06777777777777777,3,12,NA,NA,26,1907-06-08,1978-01-24,NA,NA,Paris,France, France
|
|
29
|
+
28,1934-07-03,Antonin Magne,France,4470,147.23277777777778,0.4575,3,22,NA,NA,30,1904-01-15,1983-09-08,NA,NA,Ytrac,France, France
|
|
30
|
+
29,1935-07-04,Romain Maes,Belgium,4338,141.38333333333333,0.28805555555555556,3,21,NA,NA,22,1912-08-10,1983-02-22,NA,NA,Zerkegem,Belgium, Belgium
|
|
31
|
+
30,1936-07-07,Sylvère Maes,Belgium,4442,142.79222222222222,0.4405555555555556,4,14,NA,NA,26,1909-08-27,1966-12-05,NA,NA,Zevekote,Belgium, Belgium
|
|
32
|
+
31,1937-06-30,Roger Lapébie,France,4415,138.9752777777778,0.11861111111111111,3,4,NA,NA,26,1911-01-16,1996-10-12,NA,NA,Bayonne,France, France
|
|
33
|
+
32,1938-07-05,Gino Bartali,Italy,4694,148.48666666666665,0.305,2,8,1.72,66,23,1914-07-18,2000-05-05,NA,"Gino the Pious, Ginettaccio, L'uomo di ferro, L'intramontabile",Ponte e Ema,Italy, Italy
|
|
34
|
+
33,1939-07-10,Sylvère Maes,Belgium,4224,132.05472222222224,0.5083333333333333,2,8,NA,NA,29,1909-08-27,1966-12-05,NA,NA,Zevekote,Belgium, Belgium
|
|
35
|
+
34,1947-06-25,Jean Robic,France,4642,148.1902777777778,0.050833333333333335,3,1,1.61,60,26,1921-06-10,1980-10-06,NA,"Biquet (Kid goat), Tête de cuir (Leather-head), Le farfadet de la lande Bretonne,
|
|
36
|
+
Gueule cassée",Vouziers,France, France
|
|
37
|
+
35,1948-06-30,Gino Bartali,Italy,4922,147.17666666666665,0.4405555555555556,7,9,1.72,66,33,1914-07-18,2000-05-05,NA,"Gino the Pious, Ginettaccio, L'uomo di ferro, L'intramontabile",Ponte e Ema,Italy, Italy
|
|
38
|
+
36,1949-06-30,Fausto Coppi,Italy,4808,149.68027777777777,0.16944444444444443,3,5,1.77,68,29,1919-09-15,1960-01-02,Angelo Fausto Coppi,"The Heron,Il Campionissimo
|
|
39
|
+
(Champion of Champions)",Castellania,Italy, Italy
|
|
40
|
+
37,1950-07-13,Ferdinand Kübler,Switzerland,4773,145.61555555555555,0.1525,3,11,NA,NA,30,1919-07-24,2016-12-29,NA,"Ferdi, The Cowboy, The Eagle of Adliswil, Mr 100,000 Volts[",Marthalen,Switzerland, Switzerland
|
|
41
|
+
38,1951-07-04,Hugo Koblet,Switzerland,4690,142.33722222222224,0.37277777777777776,5,11,NA,NA,26,1925-03-21,1964-11-06,NA,"Beautiful Hugo, Le pédaleur de charme",Zürich,Switzerland, Switzerland
|
|
42
|
+
39,1950-06-25,Fausto Coppi,Italy,4898,151.95555555555555,0.47444444444444445,5,14,1.77,68,30,1919-09-15,1960-01-02,Angelo Fausto Coppi,"The Heron,Il Campionissimo
|
|
43
|
+
(Champion of Champions)",Castellania,Italy, Italy
|
|
44
|
+
40,1951-07-03,Louison Bobet,France,4476,129.39027777777778,0.23722222222222222,2,5,1.79,75,26,1925-03-12,1983-03-13,NA,"Louison, Zonzon",Saint-Méen-le-Grand,France, France
|
|
45
|
+
41,1954-07-08,Louison Bobet,France,4656,140.1013888888889,0.25416666666666665,3,14,1.79,75,29,1925-03-12,1983-03-13,NA,"Louison, Zonzon",Saint-Méen-le-Grand,France, France
|
|
46
|
+
42,1955-07-07,Louison Bobet,France,4495,130.49055555555555,0.06777777777777777,2,6,1.79,75,30,1925-03-12,1983-03-13,NA,"Louison, Zonzon",Saint-Méen-le-Grand,France, France
|
|
47
|
+
43,1956-07-05,Roger Walkowiak,France,4498,124.02111111111111,0.016944444444444443,0,8,NA,NA,29,1927-03-02,2017-02-06,NA,Walko,Montluçon,France, France
|
|
48
|
+
44,1957-06-27,Jacques Anquetil,France,4669,135.74499999999998,0.23722222222222222,4,15,1.76,70,23,1934-01-08,1987-11-18,NA,"Monsieur Chrono, Maître Jacques",Mont-Saint-Aignan,France, France
|
|
49
|
+
45,1958-06-26,Charly Gaul,Luxembourg,4319,116.98472222222222,0.050833333333333335,4,2,1.73,64,25,1932-12-08,2005-12-06,NA,Angel of the Mountains,Pfaffenthal,Luxembourg, Luxembourg
|
|
50
|
+
46,1959-06-25,Federico Bahamontes,Spain,4358,123.77916666666667,0.06777777777777777,1,6,NA,NA,30,1928-07-09,NA,Alejandro Martín Bahamontes,The Eagle of Toledo,Santo Domingo-Caudilla,Spain, Spain
|
|
51
|
+
47,1960-06-26,Gastone Nencini,Italy,4173,112.14500000000001,0.08472222222222221,0,14,NA,NA,30,1930-03-01,1980-02-01,NA,"Il Leone del Mugello, Faccia di fatica (Fatigue-face)",Barberino di Mugello,Italy, Italy
|
|
52
|
+
48,1961-06-25,Jacques Anquetil,France,4397,122.02583333333334,0.20333333333333334,2,21,1.76,70,27,1934-01-08,1987-11-18,NA,"Monsieur Chrono, Maître Jacques",Mont-Saint-Aignan,France, France
|
|
53
|
+
49,1962-06-24,Jacques Anquetil,Saint-Raphaël–Helyett–Hutchinson,4274,114.53166666666667,0.06777777777777777,2,3,1.76,70,28,1934-01-08,1987-11-18,NA,"Monsieur Chrono, Maître Jacques",Mont-Saint-Aignan,France, France
|
|
54
|
+
50,1963-06-23,Jacques Anquetil,Saint-Raphaël–Gitane–R. Geminiani,4138,113.50138888888888,0.050833333333333335,4,5,1.76,70,29,1934-01-08,1987-11-18,NA,"Monsieur Chrono, Maître Jacques",Mont-Saint-Aignan,France, France
|
|
55
|
+
51,1964-06-22,Jacques Anquetil,Saint-Raphaël–Gitane–Dunlop,4504,127.16222222222223,0.015277777777777777,4,6,1.76,70,30,1934-01-08,1987-11-18,NA,"Monsieur Chrono, Maître Jacques",Mont-Saint-Aignan,France, France
|
|
56
|
+
52,1965-06-22,Felice Gimondi,Salvarani,4188,116.70166666666667,0.033888888888888885,3,18,1.81,71,22,1942-09-29,2019-08-16,NA,The Phoenix,Sedrina,Italy, Italy
|
|
57
|
+
53,1966-06-21,Lucien Aimar,Ford France–Hutchinson,4329,117.57249999999999,0.016944444444444443,0,6,NA,NA,25,1941-04-28,NA,NA,NA,Hyères,France, France
|
|
58
|
+
54,1967-06-29,Roger Pingeon,Peugeot–BP–Michelin,4779,136.8972222222222,0.050833333333333335,1,17,1.82,72,26,1940-08-28,2017-03-19,NA,"Le grand échassier, Le plombier-zingueur",Hauteville-Lompnes,France, France
|
|
59
|
+
55,1968-06-27,Jan Janssen,Pelforth–Sauvage–Lejeune,4492,133.82833333333332,0.010555555555555556,2,1,NA,NA,28,1940-05-19,NA,Johannes Adrianus Janssen,NA,Nootdorp,Netherlands, Netherlands
|
|
60
|
+
56,1969-06-28,Eddy Merckx,Faema,4117,116.26722222222222,0.28805555555555556,6,18,1.82,74,24,1945-06-17,NA,Édouard Louis Joseph Merckx,The Cannibal,Meensel-Kiezegem,Belgium, Belgium
|
|
61
|
+
57,1970-06-27,Eddy Merckx,Faemino–Faema,4254,119.53027777777778,0.20333333333333334,8,20,1.82,74,25,1945-06-17,NA,Édouard Louis Joseph Merckx,The Cannibal,Meensel-Kiezegem,Belgium, Belgium
|
|
62
|
+
58,1971-06-26,Eddy Merckx,Molteni,3608,96.7538888888889,0.1525,4,17,1.82,74,26,1945-06-17,NA,Édouard Louis Joseph Merckx,The Cannibal,Meensel-Kiezegem,Belgium, Belgium
|
|
63
|
+
59,1972-07-01,Eddy Merckx,Molteni,3846,108.28833333333333,0.16944444444444443,6,15,1.82,74,27,1945-06-17,NA,Édouard Louis Joseph Merckx,The Cannibal,Meensel-Kiezegem,Belgium, Belgium
|
|
64
|
+
60,1973-06-30,Luis Ocaña,Bic,4090,122.42611111111111,0.25416666666666665,6,14,1.65,52,28,1945-06-09,1994-06-19,Jesús Luis Ocaña Pernía,NA,Priego,Spain, Spain
|
|
65
|
+
61,1974-06-27,Eddy Merckx,Molteni,4098,116.28277777777778,0.13555555555555554,8,18,1.82,74,29,1945-06-17,NA,Édouard Louis Joseph Merckx,The Cannibal,Meensel-Kiezegem,Belgium, Belgium
|
|
66
|
+
62,1975-06-26,Bernard Thévenet,Peugeot–BP–Michelin,4000,114.59194444444444,0.033888888888888885,2,8,NA,NA,27,1948-01-10,NA,NA,Nanard,Saint-Julien-de-Civry,France, France
|
|
67
|
+
63,1976-06-24,Lucien Van Impe,Gitane–Campagnolo,4017,116.37305555555555,0.06777777777777777,1,12,NA,58,29,1946-10-20,NA,NA,de kleine van Mere,Mere,Belgium, Belgium
|
|
68
|
+
64,1977-06-30,Bernard Thévenet,Peugeot–Esso–Michelin,4096,115.64166666666668,0.013333333333333334,1,8,NA,NA,29,1948-01-10,NA,NA,Nanard,Saint-Julien-de-Civry,France, France
|
|
69
|
+
65,1978-06-29,Bernard Hinault,Renault–Gitane–Campagnolo,3908,108.3,0.050833333333333335,3,3,1.74,62,23,1954-11-14,NA,NA,"Le Blaireau (The Badger), Le Patron (The Boss)",Yffiniac,France, France
|
|
70
|
+
66,1979-06-27,Bernard Hinault,Renault–Gitane,3765,103.11388888888888,0.2202777777777778,7,17,1.74,62,24,1954-11-14,NA,NA,"Le Blaireau (The Badger), Le Patron (The Boss)",Yffiniac,France, France
|
|
71
|
+
67,1980-06-26,Joop Zoetemelk,TI–Raleigh–Creda,3842,109.32055555555556,0.10166666666666667,2,10,1.73,68,33,1946-12-03,NA,Hendrik Gerardus Joseph Zoetemelk,Joop,The Hague,Netherlands, Netherlands
|
|
72
|
+
68,1981-06-25,Bernard Hinault,Renault–Elf–Gitane,3753,96.32722222222222,0.23722222222222222,5,18,1.74,62,26,1954-11-14,NA,NA,"Le Blaireau (The Badger), Le Patron (The Boss)",Yffiniac,France, France
|
|
73
|
+
69,1982-07-02,Bernard Hinault,Renault–Elf–Gitane,3507,92.14611111111111,0.10166666666666667,4,12,1.74,62,27,1954-11-14,NA,NA,"Le Blaireau (The Badger), Le Patron (The Boss)",Yffiniac,France, France
|
|
74
|
+
70,1983-07-01,Laurent Fignon,Renault–Elf,3809,105.13111111111111,0.06777777777777777,1,6,1.74,67,22,1960-08-12,2010-08-31,Laurent Patrick Fignon,Le Professeur (The Professor),Paris,France, France
|
|
75
|
+
71,1984-06-29,Laurent Fignon,Renault–Elf,4021,112.0611111111111,0.16944444444444443,5,7,1.74,67,23,1960-08-12,2010-08-31,Laurent Patrick Fignon,Le Professeur (The Professor),Paris,France, France
|
|
76
|
+
72,1985-06-28,Bernard Hinault,La Vie Claire,4109,113.4063888888889,0.016944444444444443,2,16,1.74,62,30,1954-11-14,NA,NA,"Le Blaireau (The Badger), Le Patron (The Boss)",Yffiniac,France, France
|
|
77
|
+
73,1986-07-04,Greg LeMond,La Vie Claire,4094,110.5886111111111,0.050833333333333335,1,7,1.78,67,25,1961-06-26,NA,Gregory James LeMond,"L’Americain, LeMonster",Lakewood,USA, United States
|
|
78
|
+
74,1987-07-01,Stephen Roche,Carrera Jeans–Vagabond,4231,115.46166666666667,0.011111111111111112,1,3,1.75,74,27,1959-11-28,NA,NA,NA,Dundrum,Ireland, Ireland
|
|
79
|
+
75,1988-07-02,Pedro Delgado,Reynolds,3286,84.46472222222222,0.11861111111111111,1,11,1.71,64,28,1960-04-15,NA,Pedro Delgado Robledo,Perico,Segovia,Spain, Spain
|
|
80
|
+
76,1989-07-01,Greg LeMond,AD Renting–W-Cup–Bottecchia,3285,87.64305555555556,0.0022222222222222222,3,8,1.78,67,28,1961-06-26,NA,Gregory James LeMond,"L’Americain, LeMonster",Lakewood,USA, United States
|
|
81
|
+
77,1990-06-30,Greg LeMond,Z–Tomasso,3504,90.72222222222223,0.033888888888888885,0,2,1.78,67,29,1961-06-26,NA,Gregory James LeMond,"L’Americain, LeMonster",Lakewood,USA, United States
|
|
82
|
+
78,1991-07-06,Miguel Induráin,Banesto,3914,101.02222222222223,0.050833333333333335,2,10,1.86,80,26,1964-07-16,NA,Miguel Induráin Larraya,"Miguelón, Big Mig (English)",Villava,Spain, Spain
|
|
83
|
+
79,1992-07-04,Miguel Induráin,Banesto,3983,100.825,0.06777777777777777,3,10,1.86,80,27,1964-07-16,NA,Miguel Induráin Larraya,"Miguelón, Big Mig (English)",Villava,Spain, Spain
|
|
84
|
+
80,1993-07-03,Miguel Induráin,Banesto,3714,95.9525,0.06777777777777777,2,14,1.86,80,28,1964-07-16,NA,Miguel Induráin Larraya,"Miguelón, Big Mig (English)",Villava,Spain, Spain
|
|
85
|
+
81,1994-07-02,Miguel Induráin,Banesto,3978,103.6438888888889,0.08472222222222221,1,13,1.86,80,29,1964-07-16,NA,Miguel Induráin Larraya,"Miguelón, Big Mig (English)",Villava,Spain, Spain
|
|
86
|
+
82,1995-07-01,Miguel Induráin,Banesto,3635,92.74972222222222,0.06777777777777777,2,13,1.86,80,30,1964-07-16,NA,Miguel Induráin Larraya,"Miguelón, Big Mig (English)",Villava,Spain, Spain
|
|
87
|
+
83,1996-06-29,Bjarne Riis,Team Telekom,3765,95.95444444444445,0.016944444444444443,2,13,1.84,71,32,1964-04-03,NA,Bjarne Lykkegård Riis,"Ørnen fra Herning
|
|
88
|
+
(The Eagle from Herning)",Herning,Denmark, Denmark
|
|
89
|
+
84,1997-07-05,Jan Ullrich,Team Telekom,3950,100.50972222222222,0.1525,2,12,1.83,73,23,1973-12-02,NA,NA,"Der Kaiser, Der Jan, Der Junge, The Yoyo",Rostock,Germany, Germany
|
|
90
|
+
85,1998-07-11,Marco Pantani,Mercatone Uno–Bianchi,3875,92.82944444444443,0.050833333333333335,2,7,1.72,57,28,1970-01-13,2004-02-14,NA,"Il Pirata (The pirate), Elefantino (The little elephant)",Cesena,Italy, Italy
|
|
91
|
+
86,1999-07-03,Lance Armstrong,U.S. Postal Service,3687,91.53777777777778,0.11861111111111111,4,15,1.77,75,27,1971-09-18,NA,Lance Edward Armstrong,"Le Boss, Big Tex",Plano,USA, United States
|
|
92
|
+
87,2000-07-01,Lance Armstrong,U.S. Postal Service,3662,92.55222222222221,0.10166666666666667,1,12,1.77,75,28,1971-09-18,NA,Lance Edward Armstrong,"Le Boss, Big Tex",Plano,USA, United States
|
|
93
|
+
88,2001-07-07,Lance Armstrong,U.S. Postal Service,3458,86.2911111111111,0.10166666666666667,4,8,1.77,75,29,1971-09-18,NA,Lance Edward Armstrong,"Le Boss, Big Tex",Plano,USA, United States
|
|
94
|
+
89,2002-07-06,Lance Armstrong,U.S. Postal Service,3272,82.08666666666666,0.11861111111111111,4,11,1.77,75,30,1971-09-18,NA,Lance Edward Armstrong,"Le Boss, Big Tex",Plano,USA, United States
|
|
95
|
+
90,2003-07-05,Lance Armstrong,U.S. Postal Service,3427,83.68666666666667,0.016944444444444443,1,13,1.77,75,31,1971-09-18,NA,Lance Edward Armstrong,"Le Boss, Big Tex",Plano,USA, United States
|
|
96
|
+
91,2004-07-03,Lance Armstrong,U.S. Postal Service,3391,83.60055555555554,0.10166666666666667,5,7,1.77,75,32,1971-09-18,NA,Lance Edward Armstrong,"Le Boss, Big Tex",Plano,USA, United States
|
|
97
|
+
92,2005-07-02,Lance Armstrong,Discovery Channel,3593,86.25055555555555,0.06777777777777777,1,17,1.77,75,33,1971-09-18,NA,Lance Edward Armstrong,"Le Boss, Big Tex",Plano,USA, United States
|
|
98
|
+
93,2006-07-01,Óscar Pereiro,Caisse d'Epargne–Illes Balears,3657,89.67416666666666,0.008888888888888889,0,8,1.77,68,28,1977-08-03,NA,Óscar Pereiro Sío,NA,Mos,Spain, Spain
|
|
99
|
+
94,2007-07-07,Alberto Contador,Discovery Channel,3570,91.00722222222223,0.006388888888888889,1,4,1.76,62,24,1982-12-06,NA,Alberto Contador Velasco,El Pistolero,Pinto,Spain, Spain
|
|
100
|
+
95,2008-07-05,Carlos Sastre,Team CSC,3559,87.88111111111111,0.01611111111111111,1,5,1.73,60,33,1975-04-22,NA,Carlos Sastre Candil,NA,Leganés,Spain, Spain
|
|
101
|
+
96,2009-07-04,Alberto Contador,Astana,3459,85.80972222222222,0.06777777777777777,2,7,1.76,62,26,1982-12-06,NA,Alberto Contador Velasco,El Pistolero,Pinto,Spain, Spain
|
|
102
|
+
97,2010-07-03,Andy Schleck,Team Saxo Bank,3642,91.99083333333333,0.016944444444444443,2,12,1.86,68,25,1985-06-10,NA,Andy Raymond Schleck,NA,Luxembourg City,Luxembourg, Luxembourg
|
|
103
|
+
98,2011-07-02,Cadel Evans,BMC Racing Team,3430,86.20611111111111,0.016944444444444443,1,2,1.74,64,34,1977-02-14,NA,Cadel Lee Evans,NA,Katherine,Australia, Australia
|
|
104
|
+
99,2012-06-20,Bradley Wiggins,Team Sky,3496,87.57972222222222,0.050833333333333335,2,14,1.9,69,32,1980-04-28,NA,Bradley Marc Wiggins,Wiggo,Ghent,Belgium, Great Britain
|
|
105
|
+
100,2013-06-29,Chris Froome,Team Sky,3404,83.9388888888889,0.06777777777777777,3,14,1.86,69,28,1985-05-20,NA,Christopher Clive Froome,Froomey,Nairobi,Kenya, Great Britain
|
|
106
|
+
101,2014-07-05,Vincenzo Nibali,Astana,3660.5,89.985,0.11861111111111111,4,19,1.8,65,29,1984-11-14,NA,NA,"Lo Squalo (The Shark), 'il Roditore' (The Nibbler)",Messina,Italy, Italy
|
|
107
|
+
102,2015-07-04,Chris Froome,Team Sky,3360.3,84.77055555555556,0.016944444444444443,1,16,1.86,69,30,1985-05-20,NA,Christopher Clive Froome,Froomey,Nairobi,Kenya, Great Britain
|
|
108
|
+
103,2016-07-02,Chris Froome,Team Sky,3529,89.08,0.06777777777777777,2,14,1.86,69,31,1985-05-20,NA,Christopher Clive Froome,Froomey,Nairobi,Kenya, Great Britain
|
|
109
|
+
104,2017-07-01,Chris Froome,Team Sky,3540,86.34861111111111,0.015,0,15,1.86,69,32,1985-05-20,NA,Christopher Clive Froome,Froomey,Nairobi,Kenya, Great Britain
|
|
110
|
+
105,2018-07-07,Geraint Thomas,Team Sky,3349,83.28694444444444,0.016944444444444443,2,11,1.83,71,32,1986-05-25,NA,Geraint Howell Thomas,G,Cardiff,Wales, Great Britain
|
|
111
|
+
106,2019-07-06,Egan Bernal,Team Ineos,3349,82.95,0.016944444444444443,0,2,1.75,60,22,1997-01-13,NA,Egan Arley Bernal Gómez,NA,Bogotá,Columbia, Colombia
|
|
File without changes
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pandas as pd
|
|
3
|
+
|
|
4
|
+
from inspectpd.inspect_object.inspect_object import inspect_object
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# inspect_cat
|
|
8
|
+
def inspect_cat(df):
|
|
9
|
+
"""
|
|
10
|
+
Summary and comparison of the levels in categorical columns
|
|
11
|
+
|
|
12
|
+
Parameters
|
|
13
|
+
----------
|
|
14
|
+
|
|
15
|
+
df: A pandas dataframe.
|
|
16
|
+
|
|
17
|
+
Returns
|
|
18
|
+
----------
|
|
19
|
+
|
|
20
|
+
A pandas dataframe with columns:
|
|
21
|
+
+ col_name: object
|
|
22
|
+
column of strings containing column names of df
|
|
23
|
+
+ cnt: int64
|
|
24
|
+
integer column containing count of unique levels
|
|
25
|
+
found in each column of df.
|
|
26
|
+
+ common: object
|
|
27
|
+
column of strings containing the name of the most common level
|
|
28
|
+
+ common_pcnt: float64
|
|
29
|
+
the percentage of each column occupied by the most common level
|
|
30
|
+
shown in common.
|
|
31
|
+
+ levels: object
|
|
32
|
+
a list containing relative frequency dataframes for each column in df.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
# get the string / categorical columns
|
|
36
|
+
df_cat = df.select_dtypes(["category", "object"])
|
|
37
|
+
# new df with columns names as first col
|
|
38
|
+
out = pd.DataFrame(df_cat.columns, columns=["col_name"])
|
|
39
|
+
# tabulate values in each column
|
|
40
|
+
levels_list = []
|
|
41
|
+
for col in df_cat.columns:
|
|
42
|
+
col_vals = df_cat[col].value_counts(dropna=False).reset_index(drop=False)
|
|
43
|
+
col_vals.columns = ["value", "cnt"]
|
|
44
|
+
col_vals["pcnt"] = 100 * col_vals.cnt / np.sum(col_vals.cnt)
|
|
45
|
+
col_vals = col_vals.sort_values(["pcnt"], ascending=False)
|
|
46
|
+
col_vals = col_vals[["value", "pcnt", "cnt"]]
|
|
47
|
+
levels_list.append(col_vals)
|
|
48
|
+
# number of unique values per column
|
|
49
|
+
out["cnt"] = [x.shape[0] for x in levels_list]
|
|
50
|
+
out["common"] = [x.value[0] for x in levels_list]
|
|
51
|
+
out["common_pcnt"] = [x.pcnt[0] for x in levels_list]
|
|
52
|
+
out["levels"] = levels_list
|
|
53
|
+
out = out.sort_values("col_name").reset_index(drop=True)
|
|
54
|
+
# subclass output, adds plot methods
|
|
55
|
+
out = inspect_object(out, my_attr="inspect_cat")
|
|
56
|
+
return out
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import scipy.stats as st
|
|
3
|
+
|
|
4
|
+
from inspectpd.inspect_object.inspect_object import inspect_object
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def inspect_cor(df, method="pearson", alpha=0.05, with_col=None):
|
|
8
|
+
"""
|
|
9
|
+
Tidy correlation coefficients for numeric dataframe columns.
|
|
10
|
+
|
|
11
|
+
Parameters
|
|
12
|
+
----------
|
|
13
|
+
|
|
14
|
+
df: A pandas dataframe.
|
|
15
|
+
|
|
16
|
+
method: str, default 'pearson'
|
|
17
|
+
a character string indicating which type of correlation
|
|
18
|
+
coefficient to use, one of "pearson", "kendall", or "spearman".
|
|
19
|
+
|
|
20
|
+
alpha: float, default 0.05.
|
|
21
|
+
Alpha level for correlation confidence intervals. Defaults to 0.05.
|
|
22
|
+
|
|
23
|
+
with_col: str, default None
|
|
24
|
+
Column name to filter correlations by. Uses pandas .withcorr() under
|
|
25
|
+
the hood instead of .corr(), which can save time for large data sets.
|
|
26
|
+
|
|
27
|
+
Returns
|
|
28
|
+
----------
|
|
29
|
+
|
|
30
|
+
A pandas dataframe with columns
|
|
31
|
+
+ col_1, co1_2: object
|
|
32
|
+
character columns containing names of numeric columns in df1.
|
|
33
|
+
+ corr: float64
|
|
34
|
+
columns of correlation coefficients
|
|
35
|
+
+ p_value: float64
|
|
36
|
+
p-value associated with a test where the null hypothesis is
|
|
37
|
+
that the numeric pair have 0 correlation.
|
|
38
|
+
+ lower, upper: float64
|
|
39
|
+
lower and upper values of the confidence interval for the correlations.
|
|
40
|
+
+ pcnt_na:
|
|
41
|
+
the number of pairs of observations that were non missing for each
|
|
42
|
+
pair of columns. The correlation calculation used by .inspect_cor()
|
|
43
|
+
uses only pairwise complete observations.
|
|
44
|
+
"""
|
|
45
|
+
df_num = df.select_dtypes("number").copy()
|
|
46
|
+
if with_col is None:
|
|
47
|
+
out = df_num.corr(method=method)
|
|
48
|
+
# get the number of variables
|
|
49
|
+
nvarb = out.shape[0]
|
|
50
|
+
# unpivot the correlation matrix
|
|
51
|
+
out = out.unstack().reset_index(drop=False)
|
|
52
|
+
# rename columns
|
|
53
|
+
out.columns = ["col_1", "col_2", "corr"]
|
|
54
|
+
# row index of off diagonal elements
|
|
55
|
+
inds = [(np.arange(i + 1) + i * nvarb).tolist() for i in range(nvarb)]
|
|
56
|
+
inds = [j for i in inds for j in i]
|
|
57
|
+
# drop off diagonals
|
|
58
|
+
out = out[~out.index.isin(inds)].reset_index(drop=True)
|
|
59
|
+
else:
|
|
60
|
+
out = df_num.corrwith(df_num[with_col]).reset_index(drop=False)
|
|
61
|
+
out["col_2"] = with_col
|
|
62
|
+
# rename columns and reorder
|
|
63
|
+
out.columns = ["col_1", "corr", "col_2"]
|
|
64
|
+
out = out[["col_1", "col_2", "corr"]]
|
|
65
|
+
|
|
66
|
+
# remove self-correlations
|
|
67
|
+
out = out.query("col_1 != col_2").reset_index(drop=True)
|
|
68
|
+
# get pairwise non-na
|
|
69
|
+
df_null = 1 - df_num.isnull().astype("int")
|
|
70
|
+
nna_mat = df_null.transpose().dot(df_null)
|
|
71
|
+
nna_df = nna_mat.unstack().reset_index(drop=False)
|
|
72
|
+
nna_df.columns = ["col_1", "col_2", "nna"]
|
|
73
|
+
# add standard errors
|
|
74
|
+
nna_df = nna_df.assign(se=(1 / np.sqrt(nna_df.nna - 3)))
|
|
75
|
+
nna_df = nna_df.assign(pcnt_na=100 * nna_df.nna / df.shape[0]).drop("nna", axis=1)
|
|
76
|
+
# join pairwise nna to the output df
|
|
77
|
+
out = out.merge(nna_df, how="left", on=["col_1", "col_2"])
|
|
78
|
+
out["p_value"] = 2 * st.norm.cdf(-np.abs(out["corr"].values / out.se))
|
|
79
|
+
# swicth off divide by zero error pinged by numpy with arctans
|
|
80
|
+
np.seterr(all="ignore")
|
|
81
|
+
out["lower"] = np.tanh(
|
|
82
|
+
np.arctanh(out["corr"].values) - st.norm.ppf(1 - alpha / 2) * out.se
|
|
83
|
+
)
|
|
84
|
+
out["upper"] = np.tanh(
|
|
85
|
+
np.arctanh(out["corr"].values) + st.norm.ppf(1 - alpha / 2) * out.se
|
|
86
|
+
)
|
|
87
|
+
np.seterr(all="warn")
|
|
88
|
+
# sort by absolute value of corr
|
|
89
|
+
out = (
|
|
90
|
+
out.assign(abs_cor=np.abs(out["corr"].values))
|
|
91
|
+
.sort_values("abs_cor", ascending=False)
|
|
92
|
+
.drop(["abs_cor", "se"], axis=1)
|
|
93
|
+
.reset_index(drop=True)
|
|
94
|
+
)
|
|
95
|
+
# change order of output columns
|
|
96
|
+
out = out[["col_1", "col_2", "corr", "p_value", "lower", "upper", "pcnt_na"]]
|
|
97
|
+
# add type attribute to output
|
|
98
|
+
out = inspect_object(out, my_attr="inspect_cor")
|
|
99
|
+
return out
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pandas as pd
|
|
3
|
+
|
|
4
|
+
from inspectpd.inspect_object.inspect_object import inspect_object
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def inspect_imb(df):
|
|
8
|
+
"""
|
|
9
|
+
Summary of the most common levels in categorical columns
|
|
10
|
+
|
|
11
|
+
Parameters
|
|
12
|
+
----------
|
|
13
|
+
|
|
14
|
+
df: A pandas dataframe.
|
|
15
|
+
|
|
16
|
+
Returns
|
|
17
|
+
----------
|
|
18
|
+
|
|
19
|
+
A pandas dataframe with columns:
|
|
20
|
+
+ col_name: object
|
|
21
|
+
column of strings containing column names of df.
|
|
22
|
+
+ value: object
|
|
23
|
+
column of strings containing the most common categorical level
|
|
24
|
+
in each column of df.
|
|
25
|
+
+ cnt: int64
|
|
26
|
+
the number of occurrences of the most common categorical level
|
|
27
|
+
in each column of df1.
|
|
28
|
+
+ pcnt: float64
|
|
29
|
+
the relative frequency of each column's most common categorical
|
|
30
|
+
level expressed as a percentage.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
df_cat = df.select_dtypes(["category", "object"])
|
|
34
|
+
# new df with columns names as first col
|
|
35
|
+
out = pd.DataFrame(df_cat.columns, columns=["col_name"])
|
|
36
|
+
# tabulate values in each column
|
|
37
|
+
levels_list = []
|
|
38
|
+
for col in df_cat.columns:
|
|
39
|
+
col_vals = df_cat[col].value_counts().reset_index(drop=False)
|
|
40
|
+
col_vals.columns = ["value", "cnt"]
|
|
41
|
+
col_vals["pcnt"] = 100 * col_vals.cnt / np.sum(col_vals.cnt)
|
|
42
|
+
col_vals = col_vals.sort_values(["pcnt"], ascending=False)
|
|
43
|
+
col_vals = col_vals[["value", "pcnt", "cnt"]]
|
|
44
|
+
levels_list.append(col_vals)
|
|
45
|
+
# number of unique values per column
|
|
46
|
+
out["value"] = [x.value[0] for x in levels_list]
|
|
47
|
+
out["cnt"] = [x.cnt[0] for x in levels_list]
|
|
48
|
+
out["pcnt"] = [x.pcnt[0] for x in levels_list]
|
|
49
|
+
out = out.sort_values("pcnt", ascending=False).reset_index(drop=True)
|
|
50
|
+
# subclass output, adds plot methods
|
|
51
|
+
out = inspect_object(out, my_attr="inspect_imb")
|
|
52
|
+
return out
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
from inspectpd.inspect_object.inspect_object import inspect_object
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# inspect_mem
|
|
5
|
+
def inspect_mem(df):
|
|
6
|
+
"""
|
|
7
|
+
Summary of memory usage of dataframe columns
|
|
8
|
+
|
|
9
|
+
Parameters
|
|
10
|
+
----------
|
|
11
|
+
|
|
12
|
+
df: A pandas dataframe.
|
|
13
|
+
|
|
14
|
+
Returns
|
|
15
|
+
----------
|
|
16
|
+
|
|
17
|
+
A pandas dataframe with columns:
|
|
18
|
+
|
|
19
|
+
+ col_name: object
|
|
20
|
+
column of strings containing column names of df
|
|
21
|
+
+ bytes: int64
|
|
22
|
+
integer column containing the number of bytes in each column of df
|
|
23
|
+
+ size: object
|
|
24
|
+
column of strings containing display-friendly memory usage in SI units
|
|
25
|
+
of each column.
|
|
26
|
+
+ pcnt: float64
|
|
27
|
+
the percentage of the dataframe's total memory footprint used by each
|
|
28
|
+
column.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
out = (
|
|
32
|
+
df.memory_usage(index=False, deep=True)
|
|
33
|
+
.sort_values(ascending=False)
|
|
34
|
+
.reset_index(drop=False)
|
|
35
|
+
)
|
|
36
|
+
out.columns = ["col_name", "bytes"]
|
|
37
|
+
# add printable size strings
|
|
38
|
+
out = out.assign(size=out["bytes"].apply(format_size))
|
|
39
|
+
# add percentage of total
|
|
40
|
+
out = out.assign(pcnt=100 * out["bytes"] / out["bytes"].sum())
|
|
41
|
+
# add type attribute to output
|
|
42
|
+
out = inspect_object(out, my_attr="inspect_mem")
|
|
43
|
+
return out
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# function for making nice printable object sizes
|
|
47
|
+
def format_size(num):
|
|
48
|
+
for unit in ["", "K", "M", "G", "T", "P", "E", "Z", "Y"]:
|
|
49
|
+
if num < 1024.0:
|
|
50
|
+
if unit == "":
|
|
51
|
+
return f"{num:3.0f} {unit}B"
|
|
52
|
+
else:
|
|
53
|
+
return f"{num:3.2f} {unit}B"
|
|
54
|
+
num /= 1024.0
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from inspectpd.inspect_object.inspect_object import inspect_object
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# inspect_na
|
|
5
|
+
def inspect_na(df):
|
|
6
|
+
"""
|
|
7
|
+
Summary of the rate of missingness across dataframe columns
|
|
8
|
+
|
|
9
|
+
Parameters
|
|
10
|
+
----------
|
|
11
|
+
|
|
12
|
+
df: A pandas dataframe.
|
|
13
|
+
|
|
14
|
+
Returns
|
|
15
|
+
----------
|
|
16
|
+
|
|
17
|
+
A pandas dataframe with columns:
|
|
18
|
+
+ col_name: object
|
|
19
|
+
column of strings containing column names of df
|
|
20
|
+
+ cnt: int64
|
|
21
|
+
integer column containing the number of missing values by column.
|
|
22
|
+
+ pcnt: float64
|
|
23
|
+
the percentage of records in each column that is missing.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
df_null = df.isnull()
|
|
27
|
+
# number of nulls
|
|
28
|
+
df_nnl = (
|
|
29
|
+
df_null.sum()
|
|
30
|
+
.reset_index(drop=False)
|
|
31
|
+
.rename(columns={"index": "col_name", 0: "cnt"})
|
|
32
|
+
)
|
|
33
|
+
# proportion of nulls
|
|
34
|
+
df_mnl = (
|
|
35
|
+
df_null.mean()
|
|
36
|
+
.reset_index(drop=False)
|
|
37
|
+
.rename(columns={"index": "col_name", 0: "pcnt"})
|
|
38
|
+
)
|
|
39
|
+
# convert proportion to percentage
|
|
40
|
+
df_mnl = df_mnl.assign(pcnt=df_mnl.pcnt * 100)
|
|
41
|
+
# combine null summary into single df
|
|
42
|
+
out = df_nnl.merge(df_mnl, on="col_name", how="left")
|
|
43
|
+
out = out.sort_values("pcnt", ascending=False).reset_index(drop=True)
|
|
44
|
+
# subclass output, adds plot methods
|
|
45
|
+
out = inspect_object(out, my_attr="inspect_na")
|
|
46
|
+
return out
|