Question
Need Python Assignment Help! I've already worked on these, but would like to see an expert answer to confirm my approach. There is 3 parts
Need Python Assignment Help! I've already worked on these, but would like to see an expert answer to confirm my approach. There is 3 parts to this problem set. You will need to access a CSV file. (see link Below)
Here is the google docs link to the airline-safety.csv spreadsheet: https://docs.google.com/spreadsheets/d/1NIe8vD-RLAa8wcrJiQXUNfSHSeW_oVvPXuS9iALjOoA/edit#gid=0
1.) As the first step, load the dataset from airline-safety.csv by defining the load_data function below. Have this function return the following (in order):
- The entire data frame
- Total number of rows
- Total number of columns
def load_data(): # YOUR CODE HERE df, num_rows, num_cols = load_data()
---------------------------------------------------------------------------------------------
2.) create the function select_airlines that returns the ith to jth airline name as alist(both inclusive) from the dataframe.
For example:
if i=2 and j=5, your code should return 4 airline names: airline name from the 3rd, 4th, 5th and 6th row (assuming that the first row starts from 0).
Note on loc and iloc
Selection Using Label:
To select a column of a DataFrame by column label, the safest and fastest way is to use the .loc method. General usage looks like frame.loc[rowname,colname]. (Reminder that the colon : means "everything").
For example, if we want the color column of a data frame, we would use : ex.loc[:, 'color']
You can also slice across columns. For example, frame.loc[:, 'Name':] would give select the columns Name and the columns after.
def select_airlines(df, i, j): # YOUR CODE HERE sliced_df = select_airlines(df, 2, 5)
--------------------------------------------------------------------------------
3.) Filtering or slicing with boolean arrays
In your quest for cleaner data, you will undoubtedly filter your data at some point: whether it be for clearing up cases with missing values, culling out fishy outliers, or analyzing subgroups of your data set. Note: compound expressions have to be grouped with parentheses.
A filter example:
df[df[column name] < 5]]
Write the function fatalities_filter to return just the airline names with more than 100 and less than 300 fatalities, between the years 85 and 99. Your function needs to return alistofairline names only.
def fatalities_filter(df):
# YOUR CODE HERE
fatalities_filter(df)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started