<jupyter_start><jupyter_text>Regiment  Introduction:Special thanks to: http://chrisalbon.com/ for sharing the dataset and materials. Step 1. Import the necessary libraries<jupyter_code>import pandas as pd<jupyter_output><empty_output><jupyter_text>Step 2. Create the DataFrame with the following values:<jupyter_code>raw_data = {'regiment': ['Nighthawks', 'Nighthawks', 'Nighthawks', 'Nighthawks', 'Dragoons', 'Dragoons', 'Dragoons', 'Dragoons', 'Scouts', 'Scouts', 'Scouts', 'Scouts'], 
        'company': ['1st', '1st', '2nd', '2nd', '1st', '1st', '2nd', '2nd','1st', '1st', '2nd', '2nd'], 
        'name': ['Miller', 'Jacobson', 'Ali', 'Milner', 'Cooze', 'Jacon', 'Ryaner', 'Sone', 'Sloan', 'Piger', 'Riani', 'Ali'], 
        'preTestScore': [4, 24, 31, 2, 3, 4, 24, 31, 2, 3, 2, 3],
        'postTestScore': [25, 94, 57, 62, 70, 25, 94, 57, 62, 70, 62, 70]}<jupyter_output><empty_output><jupyter_text>Step 3. Assign it to a variable called regiment. Don't forget to name each column<jupyter_code>df = pd.DataFrame(data=raw_data)
df.head()<jupyter_output><empty_output><jupyter_text>Step 4. What is the mean preTestScore from the regiment Nighthawks?<jupyter_code>dfg = df.groupby('regiment')
dfg.preTestScore.mean()
dfg.preTestScore.mean()[['Nighthawks']]
dfg.preTestScore.mean()[1]
dfg.preTestScore.mean()[[1]]
mask = df['regiment'] == 'Nighthawks'
df[mask].preTestScore.mean()
df.preTestScore
type(dfg.preTestScore.mean())
s = dfg.preTestScore.mean()
s
s.name
s.index
s.values
s.dtypes
import seaborn as sns
s
sns.barplot(x='regiment', data=s)
d = s.reset_index()
d
sns.barplot(x='regiment', y='preTestScore', data=d)
s
sns.barplot(x=s.index, y=s.values)
df.groupby('regiment').mean()
dfg.get_group('Dragoons')
type(dfg)
type(df)
for i in df.groupby('regiment'):
    print(i)
for i in df.groupby('regiment'):
    print(i[0])
for i in df.groupby('regiment'):
    print(i[1])
for label, data in df.groupby('regiment'):
    print((label, data))
for label, data in df.groupby('regiment'):
    print(data)
df.groupby(['Nighthawks']).preTestScore.mean()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18771003360537686, 'fraction_numerical': 0.028804608737397985, 'mean_word_length': 6.016835016835016, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '143889', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 879, 'n_tokens_neox': 817, 'n_words': 185, 'path': '03_Grouping/Regiment/Exercises.ipynb', 'repo_name': 'valentin-gonzalez/pandas_exercises', 'size': '2083'}