from ipywidgets import interact

import numpy as np
import pandas as pd
import plotly.express as px
import matplotlib.pyplot as plt

%matplotlib inline
uci = 'http://archive.ics.uci.edu/ml/machine-learning-databases/'
iris = pd.read_csv(uci + 'iris/iris.data', header=None,
                  names = ['sepal lenght', 'sapal width', 
                           'petal lenght', 'petal width',
                          'class'])
iris[0:5]
sepal lenght sapal width petal lenght petal width class
0 5.1 3.5 1.4 0.2 Iris-setosa
1 4.9 3.0 1.4 0.2 Iris-setosa
2 4.7 3.2 1.3 0.2 Iris-setosa
3 4.6 3.1 1.5 0.2 Iris-setosa
4 5.0 3.6 1.4 0.2 Iris-setosa
def square(x):
    return x * x
interact(square, x=(0, 100, 10));
iris_fro = iris[0:5]
iris_sel = iris_fro[['sepal lenght','sapal width']]
iris_sel
sepal lenght sapal width
0 5.1 3.5
1 4.9 3.0
2 4.7 3.2
3 4.6 3.1
4 5.0 3.6
px.scatter(iris_sel, x='sepal lenght', y='sapal width')
px.scatter(iris, x='sepal lenght', y='sapal width', color='class', hover_name='petal lenght')
px.scatter(iris, x='sepal lenght', y='sapal width', color='sepal lenght', hover_name='petal lenght')
px.scatter(iris, x='sepal lenght', y='sapal width', color='class', size='sepal lenght', hover_name='petal width')
px.scatter_3d(iris, x='sepal lenght', z='sapal width', y='petal lenght', color='class')
px.scatter_matrix(iris, color='class')
gapminder = px.data.gapminder()
gapminder[0:10]
country continent year lifeExp pop gdpPercap iso_alpha iso_num
0 Afghanistan Asia 1952 28.801 8425333 779.445314 AFG 4
1 Afghanistan Asia 1957 30.332 9240934 820.853030 AFG 4
2 Afghanistan Asia 1962 31.997 10267083 853.100710 AFG 4
3 Afghanistan Asia 1967 34.020 11537966 836.197138 AFG 4
4 Afghanistan Asia 1972 36.088 13079460 739.981106 AFG 4
5 Afghanistan Asia 1977 38.438 14880372 786.113360 AFG 4
6 Afghanistan Asia 1982 39.854 12881816 978.011439 AFG 4
7 Afghanistan Asia 1987 40.822 13867957 852.395945 AFG 4
8 Afghanistan Asia 1992 41.674 16317921 649.341395 AFG 4
9 Afghanistan Asia 1997 41.763 22227415 635.341351 AFG 4
gapminder.query('country=="Germany"')
country continent year lifeExp pop gdpPercap iso_alpha iso_num
564 Germany Europe 1952 67.500 69145952 7144.114393 DEU 276
565 Germany Europe 1957 69.100 71019069 10187.826650 DEU 276
566 Germany Europe 1962 70.300 73739117 12902.462910 DEU 276
567 Germany Europe 1967 70.800 76368453 14745.625610 DEU 276
568 Germany Europe 1972 71.000 78717088 18016.180270 DEU 276
569 Germany Europe 1977 72.500 78160773 20512.921230 DEU 276
570 Germany Europe 1982 73.800 78335266 22031.532740 DEU 276
571 Germany Europe 1987 74.847 77718298 24639.185660 DEU 276
572 Germany Europe 1992 76.070 80597764 26505.303170 DEU 276
573 Germany Europe 1997 77.340 82011073 27788.884160 DEU 276
574 Germany Europe 2002 78.670 82350671 30035.801980 DEU 276
575 Germany Europe 2007 79.406 82400996 32170.374420 DEU 276