<jupyter_start><jupyter_text>Data For our purposes, we will be working with the [Video Game Sales Dataset](https://www.kaggle.com/gregorut/videogamesales).<jupyter_code>!pip install pandas
import pandas as pd<jupyter_output><empty_output><jupyter_text>Let's load data<jupyter_code>df = pd.read_csv("vgsales.csv")<jupyter_output><empty_output><jupyter_text>Let’s also relax the limit on the number of display columns:<jupyter_code>pd.set_option('display.max_columns', None)<jupyter_output><empty_output><jupyter_text>Data Manipulation Next, let’s print the columns in the data:<jupyter_code>list(df.columns)<jupyter_output><empty_output><jupyter_text>Let’s also print some basic information about the data<jupyter_code>df.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 16598 entries, 0 to 16597
Data columns (total 11 columns):
 #   Column        Non-Null Count  Dtype  
---  ------        --------------  -----  
 0   Rank          16598 non-null  int64  
 1   Name          16598 non-null  object 
 2   Platform      16598 non-null  object 
 3   Year          16327 non-null  float64
 4   Genre         16598 non-null  object 
 5   Publisher     16540 non-null  object 
 6   NA_Sales      16598 non-null  float64
 7   EU_Sales      16598 non-null  float64
 8   JP_Sales      16598 non-null  float64
 9   Other_Sales   16598 non-null  float64
 10  Global_Sales  16598 non-null  float64
dtypes: float64(6), int64(1), object(4)
memory usage: 1.4+ MB<jupyter_text>Now, let’s print the first five rows of data using the ‘head()’ method:<jupyter_code>df.head()<jupyter_output><empty_output><jupyter_text>Let’s select video games in the ‘sports’ genre:<jupyter_code>df_sports = df.loc[df.Genre == 'Sports']
df_sports.head()<jupyter_output><empty_output><jupyter_text>Let’s select the subset of data corresponding video games for the Wii platform:<jupyter_code>df_wii = df.loc[df.Platform == 'Wii']
df_wii.head()<jupyter_output><empty_output><jupyter_text>Let’s select ‘Racing’ games played on ‘Wii’:<jupyter_code>df_wii_racing = df_wii.loc[df.Genre == 'Racing']
df_wii_racing.head()<jupyter_output><empty_output><jupyter_text>Another way to do this in online with joint operation<jupyter_code>df_wii_racing = df.loc[(df.Platform == 'Wii') & (df.Genre == 'Racing')]
df_wii_racing.head()<jupyter_output><empty_output><jupyter_text>Let’s select Wii racing games that sold more than 1 million units globally<jupyter_code>df_gt_1mil = df.loc[(df.Platform == 'Wii') & (df.Genre == 'Racing') & (df.Global_Sales >= 1.0)]
df_gt_1mil.head()<jupyter_output><empty_output><jupyter_text>We can also select data by row using the ‘.iloc[]’ method. Let’s select the first 1000 rows of the original data:<jupyter_code>df_filter_rows = df.iloc[:1000]
print("Length of original: ", len(df))
print("Length of filtered: ", len(df_filter_rows))<jupyter_output>Length of original:  16598
Length of filtered:  1000<jupyter_text>We can also select a random sample of data, using the ‘sample()’ method:<jupyter_code>df_random_sample = df.sample(n=5000)
print("Length of sample: ", len(df_random_sample))
df_random_sample.head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11777777777777777, 'fraction_numerical': 0.040952380952380955, 'mean_word_length': 5.19056974459725, 'pattern_counts': {'":': 0, '<': 52, '<?xml version=': 0, '>': 53, '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': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '509794', 'license': 'MIT', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1131, 'n_words': 263, 'path': 'Mastering Data Selection with Pandas.ipynb', 'repo_name': 'iam-mhaseeb/Mastering-Data-Selection-with-Pandas', 'size': '3150'}