Jul 12, 2024
pip install pandas
.csv
import pandas as pd
df = pd.read_csv('pokemon_data.csv')
df.head(3)
, df.tail(3)
df = pd.read_excel('pokemon_data.xlsx')
df = pd.read_csv('pokemon_data.txt', delimiter='\t')
df.columns
df['Name']
or df.Name
df[['Name', 'Type 1', 'HP']]
df.iloc[1]
df.iloc[1:4]
df.iloc[2, 1]
for index, row in df.iterrows():
row['Name']
df.loc[df['Type 1'] == 'Fire']
df.loc[(df['Type 1'] == 'Fire') & (df['HP'] > 70)]
df.describe()
df.sort_values('Name', ascending=False)
df['Total'] = df.iloc[:, 4:10].sum(axis=1)
df.drop(columns=['Total'], inplace=True)
df.to_csv('modified.csv', index=False)
df.to_excel('modified.xlsx', index=False)
df.to_csv('modified.txt', sep='\t', index=False)
df.loc[df['Name'].str.contains('^Pi[a-z]*', flags=re.I, regex=True)]
df.loc[df['Type 1'] == 'Fire', 'Type 1'] = 'Flamer'
df.loc[df['Total'] > 500, ['Generation', 'Legendary']] = ['Test 1', 'Test 2']
df.groupby(['Type 1']).mean().sort_values('Defense', ascending=False)
df.groupby(['Type 1']).sum()
, df.groupby(['Type 1']).count()
for chunk in pd.read_csv('modified.csv', chunksize=10000)