Working with DataFrames¶
In this exercise we're going to work with a 2D-list DataFrames that you might recognize! It's the survey data from our first day.
I've taken the results of that survey and imported them into a 2D list CSV (with a little bit of clean-up).
The first row is a list of headers that describe each column. Every row after that is one of the entries that was submitted.
To access rows or entries within rows, you can use indexes and keys.
First, Get the CSV¶
- Download the following file: https://drive.google.com/file/d/1n296Qvk_9lyQRI8NgMygtZHZDZniFxRa/view?usp=sharing
- Upload it to Colab (click the 📁 icon on the left and drag it in)
Examples¶
Load the CSV:
import pandas as pd
df = pd.read_csv("ice_breaker_responses.csv")
Inspect the CSV:
df.info()
Just leave the df
as the last line in a cell to see the full contents:
df
See the columns:
df.columns
Access the first row
df.iloc[0]
Access what animal Mr. P would be:
df[df["name"] == "Mr. P"]["be_animal"]
'Cat'
Assignment¶
Use for-loops to do the following analysis:
- Count how many entries are from
"New York"
- Print the names of everyone who put
"France"
or"Paris"
as their travel destination. - Calculate the average
"stay_age"
Extra Challeng 1
- Prompt the user for a column name, print the value for every entry for that column.
Extra Challenge 2
- Prompt the user for someon's name and the column you want to know about them. Print out the value for that name and column.
Input name: Mr. P
Input column: favorite_planet
Value is Venus
In [ ]:
Copied!
In [ ]:
Copied!