<jupyter_start><jupyter_text>Mengingat NumPy<jupyter_code>import numpy as np
np_tinggi = np.array([1.73, 1.68, 1.71, 1.89, 1.79]) #m
np_berat = np.array([65.4, 59.2, 63.6, 88.4, 68.7]) #kg
bmi = np_berat / np_tinggi ** 2

bmi
bmi > 23
bmi[bmi>23]<jupyter_output><empty_output><jupyter_text>Komparasi Numerik<jupyter_code>2 < 3 
2 == 3
2 <= 3
3 <= 3
x = 2
y = 3
x >= y<jupyter_output><empty_output><jupyter_text>Komparasi yang lain<jupyter_code>'dian' > 'diantemi'
3 < 'dian' #tidak bisa 
3 < 4.1
bmi
bmi > 23
# < 
# <= 
# > 
# >= 
# == 
# !=<jupyter_output><empty_output><jupyter_text>Boolean Operator<jupyter_code># and, or, not
True and True
False and True
True and False
False and False
x = 12
x > 5 and x < 15
True or True
False or True
True or False
False or False
y = 5
y < 7 or y > 13
not True
not False<jupyter_output><empty_output><jupyter_text>Kembali ke NumPy<jupyter_code>bmi
bmi > 21
bmi < 22
bmi > 21 and bmi <22 #akan error karena memunculkan perintah ambigu
 np.logical_or(bmi > 21, bmi < 22) #np.logical_and np.logical_or np.logical_or #saran pakai np (numpy)
np.logical_and(bmi>21,bmi<22)
bmi[np.logical_and(bmi>21,bmi<22)] #based on intersection/irisan
bmi[np.logical_or(bmi > 21, bmi < 22)] #gabungan<jupyter_output><empty_output><jupyter_text>if, elif, else (conditional statement)<jupyter_code>z = 7
if z % 2 == 0 :
    print("z adalah genap")
else :
    print("z adalah ganjil")
z = 4
if z % 2 == 0:
    print("Mengecek " + str(z))
    print("z adalah genap")
z = 5 # TIDAK TEREKSEKUSI KARENA FALSE
if z % 2 == 0:
    print("Mengecek " + str(z))
    print("z adalah genap")
z = 5
if z % 2 == 0 :
    print("z adalah genap")
else :
    print("z adalah ganjil")
z = 11
if z % 2 == 0:
    print("z habis dibagi 2")
elif z % 3 == 0:
    print("z habis dibagi 3")
else :
    print("z tidak habis dibagi 2 maupun 3")
z = 6
if z % 2 == 0:
    print("z habis dibagi 2")
elif z % 3 == 0:
    print("z habis dibagi 3")
else :
    print("z tidak habis dibagi 2 maupun 3")<jupyter_output>z habis dibagi 2<jupyter_text>Filtering pandas<jupyter_code>#access from drive
#access data o link gdrive
from google.colab import drive
drive.mount('/content/gdrive')
import os
os.listdir('/content/gdrive/My Drive/DSC-UTM/Bagian-2-Python-Lanjutan/')
path_data = ('/content/gdrive/My Drive/DSC-UTM/Bagian-2-Python-Lanjutan/')
import pandas as pd
df = pd.read_csv(path_data+'negara.csv', index_col=0)
df<jupyter_output><empty_output><jupyter_text>- Tujuan: Mencari Negara dengan dengan luas diatas 8 juta km^2<jupyter_code>df['area'] #  alternatif df.loc[:,"area"] atau df.iloc[:,2]
df['area'] > 8
#fiter data dengan area >8
area_8 = df[df['area']>8]
area_8<jupyter_output><empty_output><jupyter_text>Menggunakan Boolean Operator<jupyter_code>import numpy as np
np.logical_and(df["area"] > 8, df["area"] < 10)
df[np.logical_and(df["area"] > 8, df["area"] < 10)]<jupyter_output><empty_output><jupyter_text>negara mana dengan populasi lebih dari 1000 dan area lebih dari 3.5?<jupyter_code>df[np.logical_and(df["population"]>1000,df["area"]>3.5)]<jupyter_output><empty_output><jupyter_text>Carilah kepadatan populasi(population density) dan temukan 3 negara kepadatan >100$density$ = $\frac{population}{area}$<jupyter_code>df['density'] = df['population']/df['area']
df
df['country'][df['density']>100]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15028554253080853, 'fraction_numerical': 0.0456868049293658, 'mean_word_length': 5.084095063985375, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 68, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '648107', 'license': 'MIT', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1433, 'n_words': 337, 'path': 'Pertemuan 1 - Introduction/1. Logic, Control Flow and Filtering .ipynb', 'repo_name': 'inyunita/dsc-utm-2020', 'size': '3327'}