Python 1

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/11

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 8:02 PM on 4/17/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

12 Terms

1
New cards

import fiona in terminal

python -m pip install fiona

2
New cards

format variable url with different variables like www.google.com/2024/pythontest
year = 2024
d = “python test”

url = (
f”www.google.com/{year}/{d}”

)

3
New cards

set response variable to be the api call for url

response = requests.get(url)

4
New cards

convert an api response to json, store as result

result = response.json()

5
New cards

if a json returns format [['NAME', 'state', 'county']] and you have

list = [‘20’, ‘30’, ‘40’]

How do you filter the json down to return those 3 items

[item for item in json[1:] if item[2] in list]

6
New cards

if you have a list like
[['Accomack County, Virginia', '51', '001'], ['Albemarle County, Virginia', '51', '003'], ['Alleghany County, Virginia', '51', '005']]
how would you create a dictionary with the first word of the county assigned to the last value

dictionary = {
item[0].split(",")[0]
.replace(" County", "")
: item[-1]
for item in list
}

7
New cards

if you have a dictionary like
{'Charles City': '036', 'Chesterfield': '041', 'Colonial Heights': '570'}
how would you reverse the values to be numbers then names

reversed = {num: name for name, num in dictionary.items()}

8
New cards

create a data frame from a json response
data = response.json()

df = pd.DataFrame(data, columns=data[0])

9
New cards

remove the index from a data frame called df

df = df.drop(df.index[0])

10
New cards

rename column “block group” to have no spaces in data frame df

df = df.rename(columns={"block group": "blockgroup")

11
New cards

create a field in df called “abc” that combines columns a, b, and c

df[“abc”] = df[“a”] + df[“b”] + df[“c”]

12
New cards

if you have a dictionary formatted {num: name}
and a field in a data frame for num, how would you calculate a name field to be the value in the dictionary

df[“name”] = df[“num”].map(dictionary)