Get Started With Python
Get Started With Python
Memulai Python!
Hello world!
Masalah :
In [12]: height
In [14]: famz = ["Abe", 1.84, "Beb", 1.79, "Cory", 1.82, "Dad", 1.90]
In [15]: famz
In [17]: weight
localhost:8888/notebooks/2021 Python for Data Science - ITB/Get Started with Python.ipynb# 1/5
6/21/2021 Get Started with Python
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-18-cb550bf380fe> in <module>()
----> 1 weight / height ** 2
Solusi: NumPy
Library dasar untuk perhitungan saintifik (scientific computing) dengan Python (https://numpy.org/
(https://numpy.org/))
Alternatif untuk Python List: Numpy Array untuk n-dimensi
Mudah digunakan dan bersifat open source
Jika library belum terpasang, tuliskan perintah instalasi: pip install numpy
Kemudian impor: import numpy as np
In [21]: np_height
In [23]: np_weight
In [25]: bmi
Untuk melihat fungsi lain pada NumPy, gunakan perintah np.< TAB >
In [ ]: np.
In [29]: type(np_height)
Out[29]: numpy.ndarray
In [30]: type(np_weight)
Out[30]: numpy.ndarray
localhost:8888/notebooks/2021 Python for Data Science - ITB/Get Started with Python.ipynb# 2/5
6/21/2021 Get Started with Python
In [32]: np_2d
In [33]: np_2d.shape
Out[33]: (2, 5)
SciPy
SciPy (dibaca “Sigh Pie”) merupakan library yang bersifat open source dan tersedia di https://www.scipy.org/
(https://www.scipy.org/)
SciPy dibangun untuk untuk bekerja dengan NumPy array dan menyediakan kumpulan algoritma numerik,
termasuk pemrosesan sinyal, optimasi, statistika, dan library Matplotlib untuk visualisasi data.
Jika library belum terpasang, tuliskan perintah instalasi: pip install scipy
Pandas
Pandas (Panel Data) merupakan library popular di Python yang digunakan untuk data structure dan data
analysis
Bersifat open source dan tersedia di https://pandas.pydata.org/ (https://pandas.pydata.org/)
Pandas sangat berkaitan dengan NumPy
Jika library belum terpasang, tuliskan perintah instalasi: pip install pandas
Kemudian impor: import pandas as pd
In [37]: # series
np.array([1, 2, 3, 4, 5])
In [38]: # DataFrame
np.array([[1, 2], [3, 4]])
In [52]: Tab
Out[52]:
Unnamed: 0 Negara Populasi Area Ibukota
1 MA Malaysia 25 3456 KL
In [54]: Tab["Negara"]
Out[54]: 0 Indonesia
1 Malaysia
2 Singapura
3 Jepang
4 Thailand
Name: Negara, dtype: object
localhost:8888/notebooks/2021 Python for Data Science - ITB/Get Started with Python.ipynb# 3/5
6/21/2021 Get Started with Python
In [55]: Tab.Ibukota
Out[55]: 0 Jakarta
1 KL
2 Singapura
3 Tokyo
4 Bangkok
Name: Ibukota, dtype: object
Matplotlib
Matplotlib adalah library Python untuk visualisasi data dengan dua dimensi
Bersifat open source dan tersedia di https://matplotlib.org/ (https://matplotlib.org/)
Matplotlib berkaitan dengan NumPy dan Pandas
Jika library belum terpasang, tuliskan perintah instalasi: pip install matplotlib
Kemudian impor: import matplotlib.pyplot as plt
In [67]: plt.scatter(year,price)
localhost:8888/notebooks/2021 Python for Data Science - ITB/Get Started with Python.ipynb# 4/5
6/21/2021 Get Started with Python
In [70]: plt.bar(year,price)
In [ ]:
localhost:8888/notebooks/2021 Python for Data Science - ITB/Get Started with Python.ipynb# 5/5