Learn practical skills, build real-world projects, and advance your career

Loading data into Pandas

#Setting working directory
path = 'E:\\pandas-master'
os.chdir(path)
print(os.getcwd())
E:\pandas-master
import pandas as pd

df = pd.read_csv('pokemon_data.csv')
print(df.head(5))

# df.head(9)

# df_xlsx = pd.read_excel('pokemon_data.xlsx')
# print(df_xlsx.head(3))

# df = pd.read_csv('pokemon_data.txt', delimiter='\t')
# print(df.head(5))

# df['HP']
# Name Type 1 Type 2 HP Attack Defense Sp. Atk \ 0 1 Bulbasaur Grass Poison 45 49 49 65 1 2 Ivysaur Grass Poison 60 62 63 80 2 3 Venusaur Grass Poison 80 82 83 100 3 3 VenusaurMega Venusaur Grass Poison 80 100 123 122 4 4 Charmander Fire NaN 39 52 43 60 Sp. Def Speed Generation Legendary 0 65 45 1 False 1 80 60 1 False 2 100 80 1 False 3 120 80 1 False 4 50 65 1 False

Reading Data in Pandas

#### Read Headers
# df.columns

## Read each Column
# print(df['Name'])
# print(df['Name'][0:5])

## More than one column
# print(df[['Name', 'Type 1', 'HP']])

## Read Everything in the first row
# print(df.iloc[1])

## Read Multiple Rows
# print(df.iloc[0:4])

## Iter through the rows. VERY USEFUL
# for index, row in df.iterrows():
#     print(index, row)
    
## Iter the name and row value from the dataset    
# for index, row in df.iterrows():
#     print(index, row['Name'])    
    
## Finding specefic data from our dataset taht isn't just the interger type but textual or numerical etc.    
# df.loc[df['Type 1'] == "Grass"]

## Read a specific location (R,C)
## Print the value from second row and first column
# print(df.iloc[2,1])
Venusaur