Pandas selecting rows issue

Screen Link:

My Code:
big_movers = f500.loc[['Aviva', 'HP', '', 'BHP Billiton'], ["rank", "previous_rank"]]
bottom_companies = f500.loc['National Grid' : 'AutoNation', ["rank", "sector", "country"]] 

What I expected to happen:
To create the new variables

What actually happened:

"None of [Index(['Aviva', 'HP', '', 'BHP Billiton'], dtype='object')] are in the [index]"

I’m trying to run the mission on my Jupyter environment but I have that result when I review the CSV the names are correct.

Ensure you execute each cell in order. In Jupyter notebook environment, kernel -> restart. Then run all if option is available.

I restart the Kernel and stil the same problem.

“None of [Index([‘Aviva’, ‘HP’, ‘’, ‘BHP Billiton’], dtype=‘object’)] are in the [index]”

But they’re on the CSV file and with the exact name.

toyota = f500.iloc[4]
company                                     Toyota Motor
rank                                                   5
revenues                                          254694
revenue_change                                       7.7
profits                                          16899.3
assets                                            437575
profit_change                                      -12.3
ceo                                          Akio Toyoda
industry                        Motor Vehicles and Parts
sector                            Motor Vehicles & Parts
previous_rank                                          8
country                                            Japan
hq_location                                Toyota, Japan
years_on_global_500_list                              23
employees                                         364445
total_stockholder_equity                          157210
Name: 4, dtype: object

But if I run:

toyota = f500.loc['Toyota Motor']
KeyError: 'Toyota Motor'

Any suggestion?

The code works in Dataquest mission terminal.

Most likely, your f500 has been modified in your Jupyter notebook.

Use row and column selection to access row Toyota Motor

# Series 
toyota = f500.loc["Toyota Motor",:]
# Series
toyota = f500.loc["Toyota Motor"]

Use tuple to access row Toyota Motor

Toyota Motor is a row label for multi-indexing data frame in pandas.

# Series contains "Toyota Motor"
toyota = f500.loc[("Toyota Motor")]

either works

# A Series contains "Toyota Motor"
toyota = f500.loc[("Toyota Motor", )]

.loc because row label are strings.

("Toyota Motor") is a tuple. Use tuple format to select a particular row for multi-index data frame.

("Toyota Motor", ) is a tuple. Added , to explicitly indicate its a tuple with only 1 element.

See my post on further reads on how to access elements in multi-index data frame

After restarting the kernel, you need to execute all the code cell.

import pandas as pd
f500_ = pd.read_csv(‘f500.csv’,index_col = 1)
f500 = f500_.loc[:,“rank”:“total_stockholder_equity”] = None

toyota = f500.loc[“Toyota Motor”]
drink_companies = f500.loc[[“Anheuser-Busch InBev”, “Coca-Cola”, “Heineken Holding”]]
middle_companies = f500.loc[“Tata Motors”:“Nationwide”, “rank”:“country”]

Kept facing the same challenge thus have been re-reading the data for each challenge. This is what i used for the challenge as i realized f500 data frame differed