Data Compression Quiz

Data Compression

Extracting Information from Data Quiz

Quiz


Q4

  • I got this question wrong because I thought the average ticket prices meant how much the tickets were sold for. I realize now that a higher ticket price average would indicate more popularity.

Using Programs with Data Quiz

Overview


Museum Question

  • I got this question wrong because I thought it would sort the photographers by year. I realize now that this algorithm does not filter out the unknown years, so this answer is wrong. The correct answer is D.

Binary Numbers Quiz

Binary Quiz


Binary Question

  • I got this question wrong because I forgot strings could be converted into binary. I realize now that strings can be converted to binary, such as with base64. The correct answer is 1, 2, and 3.

2.3 Pandas and Dataset Hack

import pandas as pd
df = pd.read_json('files/compResults.json')

#print compResults json file
print(df)


#printing just the competitor number and the ranking
print(df[['Competitor Number','Ranking']].to_string(index=False))
    Competitor Number  Tops  Zones  Ranking
1                1601     0      2       10
2                1602     3      4        2
3                1603     4      4        1
4                1604     2      3        4
5                1605     3      2        3
6                1606     2      2        5
7                1607     1      4        7
8                1608     2      1        6
9                1609     1      1        9
10               1610     1      3        8
 Competitor Number  Ranking
              1601       10
              1602        2
              1603        1
              1604        4
              1605        3
              1606        5
              1607        7
              1608        6
              1609        9
              1610        8
print(df.sort_values(by=['Ranking']))
    Competitor Number  Tops  Zones  Ranking
3                1603     4      4        1
2                1602     3      4        2
5                1605     3      2        3
4                1604     2      3        4
6                1606     2      2        5
8                1608     2      1        6
7                1607     1      4        7
10               1610     1      3        8
9                1609     1      1        9
1                1601     0      2       10

2.3 NBA Player Data

import pandas as pd
df = pd.read_csv('files/nba_player.csv')

#print compResults csv file
print(df)
                     name  year_start  year_end position height  weight  \
0          Alaa Abdelnaby        1991      1995      F-C   6-10   240.0   
1         Zaid Abdul-Aziz        1969      1978      C-F    6-9   235.0   
2     Kareem Abdul-Jabbar        1970      1989        C    7-2   225.0   
3      Mahmoud Abdul-Rauf        1991      2001        G    6-1   162.0   
4       Tariq Abdul-Wahad        1998      2003        F    6-6   223.0   
...                   ...         ...       ...      ...    ...     ...   
4544           Ante Zizic        2018      2018      F-C   6-11   250.0   
4545             Jim Zoet        1983      1983        C    7-1   240.0   
4546            Bill Zopf        1971      1971        G    6-1   170.0   
4547          Ivica Zubac        2017      2018        C    7-1   265.0   
4548           Matt Zunic        1949      1949      G-F    6-3   195.0   

             birth_date                                college  
0         June 24, 1968                        Duke University  
1         April 7, 1946                  Iowa State University  
2        April 16, 1947  University of California, Los Angeles  
3         March 9, 1969             Louisiana State University  
4      November 3, 1974              San Jose State University  
...                 ...                                    ...  
4544    January 4, 1997                                    NaN  
4545  December 20, 1953                  Kent State University  
4546       June 7, 1948                    Duquesne University  
4547     March 18, 1997                                    NaN  
4548  December 19, 1919           George Washington University  

[4549 rows x 8 columns]
import pandas as pd

#read csv and sort 'Duration' largest to smallest
df = pd.read_csv('files/nba_player.csv').sort_values(by=['height'], ascending=False)

print("------Height Top 10------")

print(df.head(5)[['name','position','height']].to_string(index=False))

print("------Height Bottom 10------")
print(df.tail(5)[['name','position','height']].to_string(index=False))
------Height Top 10------
            name position height
      Manute Bol        C    7-7
Gheorghe Muresan        C    7-7
        Yao Ming        C    7-6
   Shawn Bradley        C    7-6
    Chuck Nevitt        C    7-5
------Height Bottom 10------
            name position height
Frank Mangiapane        G   5-10
       Bob Royer        G   5-10
   Zeke Sinicola        G   5-10
    Rollie Seltz      G-F   5-10
   Brevin Knight        G   5-10

Reflection

  • Does it have a good sample size?
    • The competition data has a good sample size, and many components to the data, however, there could be more competitors added. But, realistically, a competition results would look like this.
    • The NBA data has a very large sample size.
  • Does the data set need to be cleaned?
    • There aren't any pieces of data that need to be cleaned at the moment, however if a string was added in the ranking category it would need to be.
  • What is the purpose of the data set?
    • The purpose of the data set was to show the number of tops, zones, and the ranking of the competitors in a climbing competition.
    • The purpose of the NBA data set is to show the stats of the all NBA players since 1950. I used pandas to only print the top five tallest and shortest players.
"""
Requests is a HTTP library for the Python programming language. 
The goal of the project is to make HTTP requests simpler and more human-friendly. 
"""
import requests

url = "https://rapidapi.com/theapiguy/api/free-nba/"

querystring = {"data":"first_name","format":"json","u":"f"}

headers = {
    "X-RapidAPI-Key": "7ebc48666emsha8cfa2f50618d2bp1656dcjsn88bf48c50b6f",
    "X-RapidAPI-Host": "free-nba.p.rapidapi.com"
}


response = requests.request("GET", url, headers=headers, params=querystring)

print("Players")

print(response.json())

# This code looks for USA in "countries_stats"
##print("Player's Height")
 #player = response.json().get('sports')
#for player in players:  # countries is a list
    #if player["name"] == "Ducks":  # this filters for USA
        #location = response.json().get('location')
       # print(location)
Players
---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
File ~/opt/anaconda3/lib/python3.9/site-packages/requests/models.py:971, in Response.json(self, **kwargs)
    970 try:
--> 971     return complexjson.loads(self.text, **kwargs)
    972 except JSONDecodeError as e:
    973     # Catch JSON-related errors and raise as requests.JSONDecodeError
    974     # This aliases json.JSONDecodeError and simplejson.JSONDecodeError

File ~/opt/anaconda3/lib/python3.9/json/__init__.py:346, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    343 if (cls is None and object_hook is None and
    344         parse_int is None and parse_float is None and
    345         parse_constant is None and object_pairs_hook is None and not kw):
--> 346     return _default_decoder.decode(s)
    347 if cls is None:

File ~/opt/anaconda3/lib/python3.9/json/decoder.py:337, in JSONDecoder.decode(self, s, _w)
    333 """Return the Python representation of ``s`` (a ``str`` instance
    334 containing a JSON document).
    335 
    336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    338 end = _w(s, end).end()

File ~/opt/anaconda3/lib/python3.9/json/decoder.py:355, in JSONDecoder.raw_decode(self, s, idx)
    354 except StopIteration as err:
--> 355     raise JSONDecodeError("Expecting value", s, err.value) from None
    356 return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

JSONDecodeError                           Traceback (most recent call last)
/Users/lydiacho/vscode/lyds.github.io/_notebooks/2023-03-09-Hacks-for-2.2-2.3.ipynb Cell 13 in <cell line: 21>()
     <a href='vscode-notebook-cell:/Users/lydiacho/vscode/lyds.github.io/_notebooks/2023-03-09-Hacks-for-2.2-2.3.ipynb#X16sZmlsZQ%3D%3D?line=16'>17</a> response = requests.request("GET", url, headers=headers, params=querystring)
     <a href='vscode-notebook-cell:/Users/lydiacho/vscode/lyds.github.io/_notebooks/2023-03-09-Hacks-for-2.2-2.3.ipynb#X16sZmlsZQ%3D%3D?line=18'>19</a> print("Players")
---> <a href='vscode-notebook-cell:/Users/lydiacho/vscode/lyds.github.io/_notebooks/2023-03-09-Hacks-for-2.2-2.3.ipynb#X16sZmlsZQ%3D%3D?line=20'>21</a> print(response.json())

File ~/opt/anaconda3/lib/python3.9/site-packages/requests/models.py:975, in Response.json(self, **kwargs)
    971     return complexjson.loads(self.text, **kwargs)
    972 except JSONDecodeError as e:
    973     # Catch JSON-related errors and raise as requests.JSONDecodeError
    974     # This aliases json.JSONDecodeError and simplejson.JSONDecodeError
--> 975     raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)

JSONDecodeError: Expecting value: line 1 column 1 (char 0)
import requests

url = "https://free-nba.p.rapidapi.com/players"

querystring = {"page":"0","per_page":"25"}

headers = {
	"content-type": "application/octet-stream",
	"X-RapidAPI-Key": "7ebc48666emsha8cfa2f50618d2bp1656dcjsn88bf48c50b6f",
	"X-RapidAPI-Host": "free-nba.p.rapidapi.com"
}

response = requests.get(url, headers=headers, params=querystring)

print("NBA Players' Position" + "\n")
player = response.json().get("data")
position = response.json().get("position")
i = 0
while i < len(player):
	for key, value in player[i].items():
		print(key, value)
	i += 1
	print("\n")
NBA Players' Position

id 14
first_name Ike
height_feet None
height_inches None
last_name Anigbogu
position C
team {'id': 12, 'abbreviation': 'IND', 'city': 'Indiana', 'conference': 'East', 'division': 'Central', 'full_name': 'Indiana Pacers', 'name': 'Pacers'}
weight_pounds None


id 25
first_name Ron
height_feet None
height_inches None
last_name Baker
position G
team {'id': 20, 'abbreviation': 'NYK', 'city': 'New York', 'conference': 'East', 'division': 'Atlantic', 'full_name': 'New York Knicks', 'name': 'Knicks'}
weight_pounds None


id 47
first_name Jabari
height_feet None
height_inches None
last_name Bird
position G
team {'id': 2, 'abbreviation': 'BOS', 'city': 'Boston', 'conference': 'East', 'division': 'Atlantic', 'full_name': 'Boston Celtics', 'name': 'Celtics'}
weight_pounds None


id 67
first_name MarShon
height_feet None
height_inches None
last_name Brooks
position G
team {'id': 15, 'abbreviation': 'MEM', 'city': 'Memphis', 'conference': 'West', 'division': 'Southwest', 'full_name': 'Memphis Grizzlies', 'name': 'Grizzlies'}
weight_pounds None


id 71
first_name Lorenzo
height_feet None
height_inches None
last_name Brown
position G
team {'id': 28, 'abbreviation': 'TOR', 'city': 'Toronto', 'conference': 'East', 'division': 'Atlantic', 'full_name': 'Toronto Raptors', 'name': 'Raptors'}
weight_pounds None


id 90
first_name Omri
height_feet None
height_inches None
last_name Casspi
position F
team {'id': 15, 'abbreviation': 'MEM', 'city': 'Memphis', 'conference': 'West', 'division': 'Southwest', 'full_name': 'Memphis Grizzlies', 'name': 'Grizzlies'}
weight_pounds None


id 1
first_name Alex
height_feet 6
height_inches 6
last_name Abrines
position G
team {'id': 21, 'abbreviation': 'OKC', 'city': 'Oklahoma City', 'conference': 'West', 'division': 'Northwest', 'full_name': 'Oklahoma City Thunder', 'name': 'Thunder'}
weight_pounds 200


id 119
first_name Tyler
height_feet None
height_inches None
last_name Davis
position C
team {'id': 21, 'abbreviation': 'OKC', 'city': 'Oklahoma City', 'conference': 'West', 'division': 'Northwest', 'full_name': 'Oklahoma City Thunder', 'name': 'Thunder'}
weight_pounds None


id 149
first_name Keenan
height_feet None
height_inches None
last_name Evans
position G
team {'id': 9, 'abbreviation': 'DET', 'city': 'Detroit', 'conference': 'East', 'division': 'Central', 'full_name': 'Detroit Pistons', 'name': 'Pistons'}
weight_pounds None


id 179
first_name Marcin
height_feet None
height_inches None
last_name Gortat
position C
team {'id': 13, 'abbreviation': 'LAC', 'city': 'LA', 'conference': 'West', 'division': 'Pacific', 'full_name': 'LA Clippers', 'name': 'Clippers'}
weight_pounds None


id 1593
first_name Andrew
height_feet None
height_inches None
last_name Bogut
position F
team {'id': 10, 'abbreviation': 'GSW', 'city': 'Golden State', 'conference': 'West', 'division': 'Pacific', 'full_name': 'Golden State Warriors', 'name': 'Warriors'}
weight_pounds None


id 241
first_name Amir
height_feet 6
height_inches 9
last_name Johnson
position C-F
team {'id': 23, 'abbreviation': 'PHI', 'city': 'Philadelphia', 'conference': 'East', 'division': 'Atlantic', 'full_name': 'Philadelphia 76ers', 'name': '76ers'}
weight_pounds 240


id 392
first_name Malachi
height_feet None
height_inches None
last_name Richardson
position G
team {'id': 29, 'abbreviation': 'UTA', 'city': 'Utah', 'conference': 'West', 'division': 'Northwest', 'full_name': 'Utah Jazz', 'name': 'Jazz'}
weight_pounds None


id 281
first_name Zach
height_feet None
height_inches None
last_name Lofton
position G
team {'id': 9, 'abbreviation': 'DET', 'city': 'Detroit', 'conference': 'East', 'division': 'Central', 'full_name': 'Detroit Pistons', 'name': 'Pistons'}
weight_pounds None


id 263
first_name Kosta
height_feet 7
height_inches 0
last_name Koufos
position C
team {'id': 26, 'abbreviation': 'SAC', 'city': 'Sacramento', 'conference': 'West', 'division': 'Pacific', 'full_name': 'Sacramento Kings', 'name': 'Kings'}
weight_pounds 245


id 382
first_name Billy
height_feet None
height_inches None
last_name Preston
position F
team {'id': 6, 'abbreviation': 'CLE', 'city': 'Cleveland', 'conference': 'East', 'division': 'Central', 'full_name': 'Cleveland Cavaliers', 'name': 'Cavaliers'}
weight_pounds None


id 384
first_name Zhou
height_feet None
height_inches None
last_name Qi
position F-C
team {'id': 11, 'abbreviation': 'HOU', 'city': 'Houston', 'conference': 'West', 'division': 'Southwest', 'full_name': 'Houston Rockets', 'name': 'Rockets'}
weight_pounds None


id 388
first_name Zach
height_feet None
height_inches None
last_name Randolph
position F
team {'id': 26, 'abbreviation': 'SAC', 'city': 'Sacramento', 'conference': 'West', 'division': 'Pacific', 'full_name': 'Sacramento Kings', 'name': 'Kings'}
weight_pounds None


id 430
first_name DJ
height_feet None
height_inches None
last_name Stephens
position G-F
team {'id': 15, 'abbreviation': 'MEM', 'city': 'Memphis', 'conference': 'West', 'division': 'Southwest', 'full_name': 'Memphis Grizzlies', 'name': 'Grizzlies'}
weight_pounds None


id 437
first_name Milos
height_feet None
height_inches None
last_name Teodosic
position G
team {'id': 13, 'abbreviation': 'LAC', 'city': 'LA', 'conference': 'West', 'division': 'Pacific', 'full_name': 'LA Clippers', 'name': 'Clippers'}
weight_pounds None


id 448
first_name Gary
height_feet None
height_inches None
last_name Trent Jr.
position G
team {'id': 25, 'abbreviation': 'POR', 'city': 'Portland', 'conference': 'West', 'division': 'Northwest', 'full_name': 'Portland Trail Blazers', 'name': 'Trail Blazers'}
weight_pounds None


id 494
first_name Michael
height_feet None
height_inches None
last_name Smith
position 
team {'id': 2, 'abbreviation': 'BOS', 'city': 'Boston', 'conference': 'East', 'division': 'Atlantic', 'full_name': 'Boston Celtics', 'name': 'Celtics'}
weight_pounds None


id 495
first_name John
height_feet None
height_inches None
last_name Morton
position 
team {'id': 6, 'abbreviation': 'CLE', 'city': 'Cleveland', 'conference': 'East', 'division': 'Central', 'full_name': 'Cleveland Cavaliers', 'name': 'Cavaliers'}
weight_pounds None


id 496
first_name Howard
height_feet None
height_inches None
last_name Wright
position 
team {'id': 1, 'abbreviation': 'ATL', 'city': 'Atlanta', 'conference': 'East', 'division': 'Southeast', 'full_name': 'Atlanta Hawks', 'name': 'Hawks'}
weight_pounds None


id 497
first_name Michael
height_feet None
height_inches None
last_name Ansley
position 
team {'id': 22, 'abbreviation': 'ORL', 'city': 'Orlando', 'conference': 'East', 'division': 'Southeast', 'full_name': 'Orlando Magic', 'name': 'Magic'}
weight_pounds None