Pandasmonium, Day 1
2025-10-17
if = 1 xfor = multiple times.strip(), .lower()for loop and a conditional to sort each letter of the word “computation” into consonants & vowels.⚠️ Avoid file-name shadowing: Don’t name your scripts pandas.py, re.py, random.py, etc.
array.
pd df (pandas dataframe), are .Series():
name="language" isn’t doing anything, but will later on.index of the .Series()pd.Series():import pandas as pd
langs = pd.Series(["Latin", "Greek", "Sanskrit", "Finnish"], index=["a","b","c","d"], name="language")
langsdict:.DataFrame() is the most popular way to create csv structure in Pythondfimport pandas as pd
langs = pd.Series(["Latin", "Greek", "Sanskrit", "Finnish"], index=["a","b","c","d"], name="language")
fam = pd.Series(["Indo-European", "Indo-European", "Indo-European", "Uralic"], index=["a","b","c","d"], name="family")
speakers = pd.Series([0, 0, 0, 6], index=["a","b","c","d"], name="speakers_millions")
languages_df = pd.concat([langs, fam, speakers], axis=1)
print(languages_df)axis=1 do?pd.concat()
pd object with other(s) to make a df.df initially:import pandas as pd
fresh_df = pd.DataFrame({
"language": ["Latin", "Greek", "Sanskrit", "Finnish"],
"family": ["Indo-European", "Indo-European", "Indo-European", "Uralic"],
"speakers_millions": [0, 0, 0, 6],
"location": ["Italy", "Greece", "India", "Finland"]
}, index=["a","b","c","d"])
print(fresh_df)Using Pandas, recreate the following table:
| sound | voicing | place | manner | |
|---|---|---|---|---|
| 0 | /p/ | voiceless | bilabial | stop |
| 1 | /b/ | voiced | bilabial | stop |
| 2 | /t/ | voiceless | alveolar | stop |
| 3 | /d/ | voiced | alveolar | stop |
| 4 | /s/ | voiceless | alveolar | fricative |
| 5 | /h/ | voiceless | glottal | fricative |
[]/{} to df.DataFrame().Series()dict to .Series()dict to a .DataFrame()?languages = {
"French": "Romance",
"Spanish": "Romance",
"Italian": "Romance",
"English": "Germanic"
}dict to dfimport pandas as pd
languages = {
"French": ["Romance"],
"Spanish": ["Romance"],
"Italian": ["Romance"],
"English": ["Germanic"]
}
lang_df = pd.DataFrame(languages)
print(lang_df)dict to dfdict.from_dict(dict, orient="index", columns = [value]) to make the key the index.DataFrame(list(dict.items()), columns = [key, value]) to set the key as one column, and the value as the seconddf, where the language & family were in separate columns.df called new_info, where you add the following values you will need to look up:
lang_updated