1/11
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
import fiona in terminal
python -m pip install fiona
format variable url with different variables like www.google.com/2024/pythontest
year = 2024
d = “python test”
url = (
f”www.google.com/{year}/{d}”
)
set response variable to be the api call for url
response = requests.get(url)
convert an api response to json, store as result
result = response.json()
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]
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
}
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()}
create a data frame from a json response
data = response.json()
df = pd.DataFrame(data, columns=data[0])
remove the index from a data frame called df
df = df.drop(df.index[0])
rename column “block group” to have no spaces in data frame df
df = df.rename(columns={"block group": "blockgroup")
create a field in df called “abc” that combines columns a, b, and c
df[“abc”] = df[“a”] + df[“b”] + df[“c”]
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)