Created
June 13, 2022 06:46
-
-
Save abenezerangelos/3592fcbdd9f9c2b94c4226504029328e to your computer and use it in GitHub Desktop.
pandas, list comprehension and dictionary comprehenstion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
student_dict = { | |
"student": ["Angela", "James", "Lily"], | |
"score": [56, 76, 98] | |
} | |
#Looping through dictionaries: | |
for (key, value) in student_dict.items(): | |
#Access key and value | |
pass | |
import pandas | |
student_data_frame = pandas.DataFrame(student_dict) | |
#Loop through rows of a data frame | |
for (index, row) in student_data_frame.iterrows(): | |
if row.student== "Angela": | |
print(row.score) | |
# Keyword Method with iterrows() | |
# {new_key:new_value for (index, row) in df.iterrows()} | |
#TODO 1. Create a dictionary in this format: | |
{"A": "Alfa", "B": "Bravo"} | |
Nato=pandas.read_csv("nato_phonetic_alphabet.csv") | |
df = pandas.DataFrame(Nato) | |
Nato_dict={v[df.columns[0]]:v[df.columns[1]] for k,v in df.iterrows()} | |
print(Nato_dict) | |
#TODO 2. Create a list of the phonetic code words from a word that the user inputs. | |
name=input("What is your name?").upper() | |
output=[Nato_dict[letter] for letter in name] | |
print(output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment