pandas to CSV
You work for an airline, and your manager has asked you to do a competitive analysis and see how often passengers flying on other airlines are involuntarily bumped from their flights. You got a CSV file (
airline_bumping.csv) from the Department of Transportation containing data on passengers that were involuntarily denied boarding in 2016 and 2017, but it doesn't have the exact numbers you want. In order to figure this out, you'll need to get the CSV into a pandas DataFrame and do some manipulation!
pandas is imported for you as
"airline_bumping.csv" is in your working directory.
TRY IT YOURSELF: Access the exercise in our Data Manipulation with pandas course here.
- Read the CSV file
"airline_bumping.csv"and store it as a DataFrame called
- Print the first few rows of
# Read CSV as DataFrame called airline_bumping airline_bumping = ____ # Take a look at the DataFrame print(____)
You're almost there! To make things easier to read, you'll need to sort the data and export it to CSV so that your colleagues can read it.
airline_totalsby the values of
bumps_per_10kfrom highest to lowest, storing as airline_totals_sorted.
- Print your sorted DataFrame.
- Save the sorted DataFrame as a CSV called
# Create airline_totals_sorted airline_totals_sorted = ____ # Print airline_totals_sorted ____ # Save as airline_totals_sorted.csv ____
To learn more about reading and writing CSVs, please see this video from our course Data Manipulation with pandas.