3
3
"""
4
4
5
5
6
- def gapminder (datetimes = False , centroids = False , year = None ):
6
+ def gapminder (datetimes = False , centroids = False , year = None , pretty_names = False ):
7
7
"""
8
8
Each row represents a country on a given year.
9
9
@@ -24,10 +24,27 @@ def gapminder(datetimes=False, centroids=False, year=None):
24
24
df ["year" ] = (df ["year" ].astype (str ) + "-01-01" ).astype ("datetime64[ns]" )
25
25
if not centroids :
26
26
df = df .drop (["centroid_lat" , "centroid_lon" ], axis = 1 )
27
+ if pretty_names :
28
+ df .rename (
29
+ mapper = dict (
30
+ country = "Country" ,
31
+ continent = "Continent" ,
32
+ year = "Year" ,
33
+ lifeExp = "Life Expectancy" ,
34
+ gdpPercap = "GDP per Capita" ,
35
+ pop = "Population" ,
36
+ iso_alpha = "ISO Alpha Country Code" ,
37
+ iso_num = "ISO Numeric Country Code" ,
38
+ centroid_lat = "Centroid Latitude" ,
39
+ centroid_lon = "Centroid Longitude" ,
40
+ ),
41
+ axis = "columns" ,
42
+ inplace = True ,
43
+ )
27
44
return df
28
45
29
46
30
- def tips ():
47
+ def tips (pretty_names = False ):
31
48
"""
32
49
Each row represents a restaurant bill.
33
50
@@ -36,7 +53,23 @@ def tips():
36
53
Returns:
37
54
A `pandas.DataFrame` with 244 rows and the following columns:
38
55
`['total_bill', 'tip', 'sex', 'smoker', 'day', 'time', 'size']`."""
39
- return _get_dataset ("tips" )
56
+
57
+ df = _get_dataset ("tips" )
58
+ if pretty_names :
59
+ df .rename (
60
+ mapper = dict (
61
+ total_bill = "Total Bill" ,
62
+ tip = "Tip" ,
63
+ sex = "Payer Gender" ,
64
+ smoker = "Smokers at Table" ,
65
+ day = "Day of Week" ,
66
+ time = "Meal" ,
67
+ size = "Party Size" ,
68
+ ),
69
+ axis = "columns" ,
70
+ inplace = True ,
71
+ )
72
+ return df
40
73
41
74
42
75
def iris ():
0 commit comments