Lekcja PANDAS i DataFrame

 
import pandas as pd

df = pd.DataFrame(
[
[1, 'Math for Juniors', 3, False],
[2, 'Geometry in Nature', 1, False],
[3, 'Just a Chance. Probablity in Praxis.',1, True],
[4, 'Linear functions with fun', 5, True],
[5, 'About zero', 2, False],
[6, 'Logic for begginers', 3, False]
]
)

df

df.columns = ['Id', 'Name', 'Amount', 'Promo']

df

df[['Name', 'Amount']]

df.iloc[1:,1]

df.iloc[:, 2]

df[df.Amount > 1]

df.Amount

df.Amount > 1

df[ (df.Amount>1) | (df.Promo == True)]

df

df [ (df.Amount > 2) & (df.Promo == False)]

type(df)

Rozwiązanie

 
import pandas as pd

uni = pd.read_csv('./data/WorldUniversityRanking.csv', encoding='UTF-8')

uni.head()

uni[uni.country == 'Poland']

uni[(uni.country == 'Poland') & (uni.year == 2015)]

uni[(uni.country == 'Poland') & (uni.year == 2015) & (uni.publications > 700)]

uni[(uni.country == 'Poland') & (uni.year == 2015) & ((uni.publications > 700) | (uni.patents > 300))]