Summary and Maps
Summary
describe()
To summary, use describe
reviews.describe()
reviews.price.describe()
reviews.country.describe()
unique()
To get unique values
reviews.country.unique()
# ---
array(['Kerin O’Keefe', 'Roger Voss', 'Paul Gregutt',
'Alexander Peartree', 'Michael Schachner', 'Anna Lee C. Iijima',
'Virginie Boone', 'Matt Kettmann', nan, 'Sean P. Sullivan',
'Jim Gordon', 'Joe Czerwinski', 'Anne Krebiehl\xa0MW',
'Lauren Buzzeo', 'Mike DeSimone', 'Jeff Jenssen',
'Susan Kostrzewa', 'Carrie Dykes', 'Fiona Adams',
'Christina Pickard'], dtype=object)
value_counts()
To see a list of unique values and how often they occur in the dataset, we can use the value_counts() method
reviews.taster_name.value_counts()
# ---
Roger Voss 25514
Michael Schachner 15134
...
Fiona Adams 27
Christina Pickard 6
Name: taster_name, Length: 19, dtype: int64
Map
A map is a term, borrowed from mathematics, for a function that takes one set of values and "maps" them to another set of values
map()
review_points_mean = reviews.points.mean()
reviews.points.map(lambda p: p - review_points_mean)
# ---
0 -1.447138
1 -1.447138
...
129969 1.552862
129970 1.552862
Name: points, Length: 129971, dtype: float64
apply()
apply() is the equivalent method if we want to transform a whole DataFrame by calling a custom method on each row
def remean_points(row):
row.points = row.points - review_points_mean
return row
reviews.apply(remean_points, axis='columns')
note
If we had called reviews.apply() with axis='index', then instead of passing a function to transform each row, we would need to give a function to transform each column.
To combining country and region information in the dataset would be to do the following
reviews.country + " - " + reviews.region_1