Skip to content

Instantly share code, notes, and snippets.

@rshdschwdhry
Last active October 23, 2019 11:29
Show Gist options
  • Save rshdschwdhry/1d98111a42afa5ef79d63c6001cfffa7 to your computer and use it in GitHub Desktop.
Save rshdschwdhry/1d98111a42afa5ef79d63c6001cfffa7 to your computer and use it in GitHub Desktop.
trying-out-python-and-pandas
'''
hi, i'm just starting to learn programming and i know that i want to learn python. i took this online python intro workshop from general assembly.
we were tasked to solve this question. i've already finished 1, 2, 3, & 4.
i'm having difficulty figuring out how to answer 5. let me clarify, i don't even know what to type in google to figure out how to work on this last part.
i've tried visiting pandas documentation, i can use the solution from 3 & 4 to get the students with same subjects, but my problem is the 'and'.
here's the question: Print out all the students who are taking the same courses in the following format: "Todd and Jamie are taking Physics. Vincent and Allen and Sarah are taking Chemistry." etc.
link to the repo (https://github.com/kasun-maldeni/intro-to-python)
'''
# from the repo
import pandas
data = pandas.read_csv("https://raw.githubusercontent.com/kasun-maldeni/intro-to-python/master/data.csv")
print(data.values)
# i just tried this one out.
print('------')
print(data)
# and this one too.
print('------')
for row, label in data.iterrows():
print(label, row)
print()
# this is 1 & 2.
print('------')
for label, row in data.iterrows():
print(row["name"].capitalize(), " is studying ", row["subjects"].capitalize(), " in ", row["location"].capitalize(), ".")
# this is 3.
print('------')
students_from_toronto = data[data['location']=='toronto'].name.tolist()
print(students_from_toronto)
for x in students_from_toronto:
print(x.capitalize())
# this is 4.
print('------')
students_from_melbourne = data[data['location']=='melbourne'].name.tolist()
print(students_from_melbourne)
for x in students_from_melbourne:
print(x.capitalize())
# this is 5. don't know what to do next.
print('------')
data_sort = data.sort_values(by=['subjects'])
print(data_sort)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment