0

How the dataset looks

I am working with a dataset from Kaggle (https://www.kaggle.com/ash316/learn-pandas-with-pokemons). I would like to be able to graph the ATTACK vs DEFENSE of the highest rated pokemon (ranked by TOTAL). I would like this graph to have dots labeled with the names of the pokemon. However, I do not know how to return the values of the NAME columns associated with the TOTAL. For instance, I would like something like 780 to return both Mega Rayquaza and Mega Mewtwo Y.

The code that formats the data set into this is:

import pandas as pd   #importing all the important packages
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
plt.style.use('fivethirtyeight')

df =  pd.read_csv('../input/Pokemon.csv')  #read the csv file and save it into a variable

df.columns = df.columns.str.upper().str.replace('_', '') #change into upper case

df = df.set_index('NAME') #change and set the index to the name attribute

df.index = df.index.str.replace(".*(?=Mega)", "")

df=df.drop(['#'],axis=1) #drop the columns with axis=1;axis=0 is for rows

df['TYPE 2'].fillna(df['TYPE 1'], inplace=True) #fill NaN values in Type2 with corresponding values of Type

strong=df.sort_values(by='TOTAL', ascending=False) #sorting the rows in descending order
strong.drop_duplicates(subset=['TYPE 1'],keep='first') #since the rows are now sorted in descending oredr
#thus we take the first row for every new type of pokemon i.e the table will check TYPE 1 of every pokemon
#The first pokemon of that type is the strongest for that type
#so we just keep the first row

I apologize if this is confusing or has been asked before, I could not seem to find a way to properly express my question (that I'm sure is very basic). Again if the code is weird you can find it on the link above.

Steak
  • 514
  • 3
  • 15
  • Answer is here https://stackoverflow.com/questions/17071871/how-to-select-rows-from-a-dataframe-based-on-column-values – João Ramiro May 06 '20 at 23:20

1 Answers1

1

This will return an Series which can be read just like an array, with the pokemon names

#will return all rows where total is equal to some value
df1 =df.loc[df['TOTAL'] == some_value]

#if you wish to get to pokemons for that value just do
names = df1['NAME']
João Ramiro
  • 312
  • 1
  • 9