<jupyter_start><jupyter_text>Dataframes Operations<jupyter_code>bestSellingGamesData = {
    'Naughty Dog':             ['Uncharted 4',   '16m',   'Action', '2016-05-10'],
    'Insomniac Games':         ['Spider-Man',    '13.2m', 'Action', '2019-09-07'],
    'CD Projekt Red':          ['The Witcher 3', '11m',   'RPG',    '2015-05-19'],
    'SIE Santa Monica Studio': ['God of War',    '10m',   'Action', '2018-04-20']
}
gamesDataframe = pd.DataFrame(bestSellingGamesData); gamesDataframe
gamesDataframe.dtypes
gamesDataframe.index
# Informations about SIE Santa Monica Studio:
gamesDataframe['SIE Santa Monica Studio']
# Naughty Dog's best selling game ammount:
gamesDataframe['Naughty Dog'][1]
# Release dates for each index (in this case, the producers):
gamesDataframe.iloc[3]
# Just the name and sales ammount of each producer's best selling game:
gamesDataframe[:2]<jupyter_output><empty_output><jupyter_text>Changing the Indexes<jupyter_code>gamesDataframe.insert(0, 'ID', ['Name', 'Sales', 'Genre', 'Release Date']); gamesDataframe
gamesDataframeNewId = pd.DataFrame(gamesDataframe.set_index('ID')); gamesDataframeNewId<jupyter_output><empty_output><jupyter_text>Manipulation and Organization<jupyter_code>bestSellingGamesData = {
    'Naughty Dog':             ['Uncharted 4',        16,   'Action',  '2016-05-10'],
    'Insomniac Games':         ['Spider-Man',         13.2, 'Action',  '2019-09-07'],
    'CD Projekt Red':          ['The Witcher 3',      11,   'RPG',     '2015-05-19'],
    'SIE Santa Monica Studio': ['God of War',         10,   'Action',  '2018-04-20'],
    'Guerrilla Games':         ['Horizon Zero Dawn',  10,   'RPG',     '2017-02-28'],
    'Polyphony Digital':       ['Gran Turismo Sport', 8,    'Car Race', '2017-10-17'],
    'Capcom':                  ['Monster Hunter',     4.6,  'RPG',      '2018-01-26'],
}
gamesDataframe = pd.DataFrame(bestSellingGamesData); gamesDataframe
gamesDataframeTransposed = gamesDataframe.T; gamesDataframeTransposed.head()
gamesDataframeTransposed.columns
gamesDataframeTransposed.columns = ['Name', 'Sales (m)', 'Genre', 'Release Date']; gamesDataframeTransposed
# gamesDataframeTransposed.Name or:
gamesDataframeTransposed['Name']
gamesDataframeTransposed['Rating'] = [9.8, 9.6, 9.6, 9.6, 9.5, 9.3, 8.9]; gamesDataframeTransposed
gamesDataframeTransposed.dtypes
gamesDataframe = gamesDataframeTransposed.copy();
newIds = [
    'Naughty Dog'.upper(),
    'Insomniac Games'.upper(), 
    'CD Projekt Red'.upper(), 
    'SIE Santa Monica Studio'.upper(), 
    'Guerrilla Games'.upper(), 
    'Polyphony Digital'.upper(), 
    'Capcom'.upper()
]
gamesDataframe.index = newIds; gamesDataframe
gamesDataframe.iloc[3:5]
gamesDataframe.sort_values('Name')
gamesDataframe.sort_values('Sales (m)', ascending = False)
gamesDataframe.sort_index()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15172900494001412, 'fraction_numerical': 0.04763585038814397, 'mean_word_length': 4.299065420560748, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '236018', 'license': 'MIT', 'n_tokens_mistral': 1067, 'n_tokens_neox': 950, 'n_words': 207, 'path': 'modules/02-data-organization-and-visualization/10-pandas-dataframes-indexing.ipynb', 'repo_name': 'cfascina/rtaps', 'size': '2834'}