'''Pandas is used to gather data sets through its DataFrames implementation'''
import pandas as pd
df = pd.read_json('files/games.json')

print(df)
       Game Name  Average Monthly Players       Developers
0       Fortnite                276931944       Epic Games
1   Apex Legends                   624473  Electronic Arts
2  Rocket League                    25670       Epic Games
3      Minecraft                  1405619           Mojang
4   Call of Duty                   316225       Activision
5      Destiny 2                  1653214           Bungie

DataFrame Column Selection

print(df[['Game Name']])
print()
print(df[['Average Monthly Players']])
print()
print(df[['Developers']])
       Game Name
0       Fortnite
1   Apex Legends
2  Rocket League
3      Minecraft
4   Call of Duty
5      Destiny 2

   Average Monthly Players
0                276931944
1                   624473
2                    25670
3                  1405619
4                   316225
5                  1653214

        Developers
0       Epic Games
1  Electronic Arts
2       Epic Games
3           Mojang
4       Activision
5           Bungie

Multiple Columns

print(df[['Game Name','Developers']].to_string(index=False))
    Game Name      Developers
     Fortnite      Epic Games
 Apex Legends Electronic Arts
Rocket League      Epic Games
    Minecraft          Mojang
 Call of Duty      Activision
    Destiny 2          Bungie

DataFrame Sort

print(df.sort_values(by=['Average Monthly Players'], ascending=False))

print()

#sort the values in reverse order
print(df.sort_values(by=['Average Monthly Players']))
       Game Name  Average Monthly Players       Developers
0       Fortnite                276931944       Epic Games
5      Destiny 2                  1653214           Bungie
3      Minecraft                  1405619           Mojang
1   Apex Legends                   624473  Electronic Arts
4   Call of Duty                   316225       Activision
2  Rocket League                    25670       Epic Games

       Game Name  Average Monthly Players       Developers
2  Rocket League                    25670       Epic Games
4   Call of Duty                   316225       Activision
1   Apex Legends                   624473  Electronic Arts
3      Minecraft                  1405619           Mojang
5      Destiny 2                  1653214           Bungie
0       Fortnite                276931944       Epic Games

DataFrame Selection or Filter

df = pd.read_json('files/games.json')
print(df[df.Metacritic > 87])
      Game Name  Average Monthly Players       Developers  Metacritic
1  Apex Legends                   624473  Electronic Arts          88
3     Minecraft                  1405619           Mojang          93
6         CS-GO                  1416861            Valve          88

DataFrame Selection Max and Min

print(df[df.Metacritic == df.Metacritic.max()])
print()
print(df[df.Metacritic == df.Metacritic.min()])
   Game Name  Average Monthly Players Developers  Metacritic
3  Minecraft                  1405619     Mojang          93

      Game Name  Average Monthly Players  Developers  Metacritic
4  Call of Duty                   316225  Activision          73

Head and Tail

import pandas as pd

#read csv and sort 'Duration' largest to smallest
df = pd.read_json('files/games.json').sort_values(by=['Metacritic'], ascending=False)


print("-----Top Scoring 2-----")
print(df.head(2))

print()
print()

print("-----Bottom Scoring 2-----")
print(df.tail(2))
-----Top Scoring 2-----
      Game Name  Average Monthly Players       Developers  Metacritic
3     Minecraft                  1405619           Mojang          93
1  Apex Legends                   624473  Electronic Arts          88


-----Bottom Scoring 2-----
      Game Name  Average Monthly Players  Developers  Metacritic
0      Fortnite                276931944  Epic Games          83
4  Call of Duty                   316225  Activision          73