big_movers = f500.loc[['Aviva', 'HP', 'JD.com', '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', 'JD.com', '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,
restart. Then run all if option is available.
I restart the Kernel and stil the same problem.
“None of [Index([‘Aviva’, ‘HP’, ‘JD.com’, ‘BHP Billiton’], dtype=‘object’)] are in the [index]”
But they’re on the CSV file and with the exact name.
toyota = f500.iloc
company Toyota Motor
ceo Akio Toyoda
industry Motor Vehicles and Parts
sector Motor Vehicles & Parts
hq_location Toyota, Japan
Name: 4, dtype: object
But if I run:
toyota = f500.loc['Toyota Motor']
KeyError: 'Toyota Motor'
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
toyota = f500.loc["Toyota Motor",:]
toyota = f500.loc["Toyota Motor"]
Use tuple to access row
Toyota Motor is a row label for multi-indexing data frame in pandas.
# Series contains "Toyota Motor"
toyota = f500.loc[("Toyota Motor")]
# A Series contains "Toyota Motor"
toyota = f500.loc[("Toyota Motor", )]
.loc because row label are strings.
("Toyota Motor") is a
tuple format to select a particular row for multi-index data frame.
("Toyota Motor", ) is a
, 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”]
f500.index.name = 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