<jupyter_start><jupyter_text>**[Pandas Home Page](https://www.kaggle.com/learn/pandas)**---  IntroductionIn these exercises we'll apply groupwise analysis to our dataset.Run the code cell below to load the data before running the exercises.<jupyter_code>import pandas as pd

reviews = pd.read_csv("../input/wine-reviews/winemag-data-130k-v2.csv", index_col=0)
#pd.set_option("display.max_rows", 5)

from learntools.core import binder; binder.bind(globals())
from learntools.pandas.grouping_and_sorting import *
print("Setup complete.")<jupyter_output><empty_output><jupyter_text>Exercises  1.Who are the most common wine reviewers in the dataset? Create a `Series` whose index is the `taster_twitter_handle` category from the dataset, and whose values count how many reviews each person wrote.<jupyter_code># Your code here
reviews_written = reviews.groupby('taster_twitter_handle').size()

# Check your answer
q1.check()
#q1.hint()
#q1.solution()<jupyter_output><empty_output><jupyter_text>2.What is the best wine I can buy for a given amount of money? Create a `Series` whose index is wine prices and whose values is the maximum number of points a wine costing that much was given in a review. Sort the values by price, ascending (so that `4.0` dollars is at the top and `3300.0` dollars is at the bottom).<jupyter_code>best_rating_per_price = reviews.groupby('price')['points'].max().sort_index()

# Check your answer
q2.check()
#q2.hint()
#q2.solution()<jupyter_output><empty_output><jupyter_text>3.What are the minimum and maximum prices for each `variety` of wine? Create a `DataFrame` whose index is the `variety` category from the dataset and whose values are the `min` and `max` values thereof.<jupyter_code>price_extremes = reviews.groupby('variety').price.agg([min, max])

# Check your answer
q3.check()
#q3.hint()
#q3.solution()<jupyter_output><empty_output><jupyter_text>4.What are the most expensive wine varieties? Create a variable `sorted_varieties` containing a copy of the dataframe from the previous question where varieties are sorted in descending order based on minimum price, then on maximum price (to break ties).<jupyter_code>sorted_varieties = reviews.groupby('variety').price.agg([min, max]).sort_values(by=['min', 'max'], ascending=False)

# Check your answer
q4.check()
#q4.hint()
#q4.solution()<jupyter_output><empty_output><jupyter_text>5.Create a `Series` whose index is reviewers and whose values is the average review score given out by that reviewer. Hint: you will need the `taster_name` and `points` columns.<jupyter_code>reviewer_mean_ratings = reviews.groupby('taster_name').points.mean()

# Check your answer
q5.check()
#q5.hint()
#q5.solution()<jupyter_output><empty_output><jupyter_text>Are there significant differences in the average scores assigned by the various reviewers? Run the cell below to use the `describe()` method to see a summary of the range of values.<jupyter_code>reviewer_mean_ratings.describe()<jupyter_output><empty_output><jupyter_text>6.What combination of countries and varieties are most common? Create a `Series` whose index is a `MultiIndex`of `{country, variety}` pairs. For example, a pinot noir produced in the US should map to `{"US", "Pinot Noir"}`. Sort the values in the `Series` in descending order based on wine count.<jupyter_code>country_variety_counts = reviews.groupby(['country', 'variety']).size().sort_values(ascending=False)

# Check your answer
q6.check()
#q6.hint()
#q6.solution()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10917404972849386, 'fraction_numerical': 0.010574449842812233, 'mean_word_length': 6.415254237288136, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '2586', 'license': 'MIT', 'n_tokens_mistral': 1119, 'n_tokens_neox': 1088, 'n_words': 363, 'path': '04 Pandas Certificate/Exercise Grouping and Sorting.ipynb', 'repo_name': 'mateuszczubkowski/introduction-to-python', 'size': '3499'}