'DataFrame filter column

I have the following dataframe 'X_df'

which city has the 5th highest total number of Walmart stores (super stores and regular stores combined)?

data_url = 'https://raw.githubusercontent.com/plotly/datasets/master/1962_2006_walmart_store_openings.csv'
x_df = pd.read_csv(data_url, header=0)

x_df['STRSTATE'].where(x_df['type_store'] == 7)



Solution 1:[1]

Edit:

I think something like this is what you want? :

data_url = 'https://raw.githubusercontent.com/plotly/datasets/master/1962_2006_walmart_store_openings.csv'
x_df = pd.read_csv(data_url, header=0)

city_store_count = x_df.groupby(['STRCITY']).size().sort_values(ascending = False).to_frame()
city_store_count.columns = ['Stores_in_City']
city_store_count.iloc[4]

The fifth biggest is actually a shared 3rd place with ten stores, so you could print the top 10 for instance:

city_store_count.head(10)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1