Commit 6f978449 authored by A.CHAITANYA KUMAR's avatar A.CHAITANYA KUMAR
Browse files

Upload New File

parent 8e71c277
{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [],
"source": [
"records = [{'Name':'Ganesh', 'Age':27, 'Favourite Color': 'red'},\n",
" {'Name':'Bhanu', 'Age':21},\n",
" {'Name':'Vishalini', 'Age':20},\n",
" {'Name':'Ravali', 'Age':19, 'Favourite Color': 'pink'},\n",
" {'Name':'Prashant', 'Age':19, 'Favourite Color': 'black'},\n",
" {'Name':'Murali', 'Age':50, 'Favourite Color': 'black'}]"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"data = pd.DataFrame(records)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"data['Age'] = data['Age'] + 5"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Age</th>\n",
" <th>Favourite Color</th>\n",
" <th>Name</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>32</td>\n",
" <td>red</td>\n",
" <td>Ganesh</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>26</td>\n",
" <td>blue</td>\n",
" <td>Bhanu</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>25</td>\n",
" <td>blue</td>\n",
" <td>Vishalini</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>24</td>\n",
" <td>pink</td>\n",
" <td>Ravali</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>24</td>\n",
" <td>black</td>\n",
" <td>Prashant</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>55</td>\n",
" <td>black</td>\n",
" <td>Murali</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Age Favourite Color Name\n",
"0 32 red Ganesh\n",
"1 26 blue Bhanu\n",
"2 25 blue Vishalini\n",
"3 24 pink Ravali\n",
"4 24 black Prashant\n",
"5 55 black Murali"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"data['Favourite Color'] = data['Favourite Color'].fillna('blue')"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Age</th>\n",
" <th>Favourite Color</th>\n",
" <th>Name</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>32</td>\n",
" <td>red</td>\n",
" <td>Ganesh</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>26</td>\n",
" <td>blue</td>\n",
" <td>Bhanu</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>25</td>\n",
" <td>blue</td>\n",
" <td>Vishalini</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>24</td>\n",
" <td>pink</td>\n",
" <td>Ravali</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>24</td>\n",
" <td>black</td>\n",
" <td>Prashant</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>55</td>\n",
" <td>black</td>\n",
" <td>Murali</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Age Favourite Color Name\n",
"0 32 red Ganesh\n",
"1 26 blue Bhanu\n",
"2 25 blue Vishalini\n",
"3 24 pink Ravali\n",
"4 24 black Prashant\n",
"5 55 black Murali"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Age</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>count</th>\n",
" <td>6.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>mean</th>\n",
" <td>31.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>std</th>\n",
" <td>12.132601</td>\n",
" </tr>\n",
" <tr>\n",
" <th>min</th>\n",
" <td>24.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25%</th>\n",
" <td>24.250000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50%</th>\n",
" <td>25.500000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>75%</th>\n",
" <td>30.500000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>max</th>\n",
" <td>55.000000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Age\n",
"count 6.000000\n",
"mean 31.000000\n",
"std 12.132601\n",
"min 24.000000\n",
"25% 24.250000\n",
"50% 25.500000\n",
"75% 30.500000\n",
"max 55.000000"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.describe()"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Age</th>\n",
" <th>Favourite Color</th>\n",
" <th>Name</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>26</td>\n",
" <td>blue</td>\n",
" <td>Bhanu</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>25</td>\n",
" <td>blue</td>\n",
" <td>Vishalini</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Age Favourite Color Name\n",
"1 26 blue Bhanu\n",
"2 25 blue Vishalini"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data[data['Favourite Color'] == 'blue']"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<pandas.core.groupby.groupby.DataFrameGroupBy object at 0x7f7e520e4f60>"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"d = data.groupby(['Favourite Color'])\n",
"d"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead tr th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe thead tr:last-of-type th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr>\n",
" <th></th>\n",
" <th colspan=\"8\" halign=\"left\">Age</th>\n",
" </tr>\n",
" <tr>\n",
" <th></th>\n",
" <th>count</th>\n",
" <th>mean</th>\n",
" <th>std</th>\n",
" <th>min</th>\n",
" <th>25%</th>\n",
" <th>50%</th>\n",
" <th>75%</th>\n",
" <th>max</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Favourite Color</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>black</th>\n",
" <td>2.0</td>\n",
" <td>39.5</td>\n",
" <td>21.920310</td>\n",
" <td>24.0</td>\n",
" <td>31.75</td>\n",
" <td>39.5</td>\n",
" <td>47.25</td>\n",
" <td>55.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>blue</th>\n",
" <td>2.0</td>\n",
" <td>25.5</td>\n",
" <td>0.707107</td>\n",
" <td>25.0</td>\n",
" <td>25.25</td>\n",
" <td>25.5</td>\n",
" <td>25.75</td>\n",
" <td>26.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>pink</th>\n",
" <td>1.0</td>\n",
" <td>24.0</td>\n",
" <td>NaN</td>\n",
" <td>24.0</td>\n",
" <td>24.00</td>\n",
" <td>24.0</td>\n",
" <td>24.00</td>\n",
" <td>24.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>red</th>\n",
" <td>1.0</td>\n",
" <td>32.0</td>\n",
" <td>NaN</td>\n",
" <td>32.0</td>\n",
" <td>32.00</td>\n",
" <td>32.0</td>\n",
" <td>32.00</td>\n",
" <td>32.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Age \n",
" count mean std min 25% 50% 75% max\n",
"Favourite Color \n",
"black 2.0 39.5 21.920310 24.0 31.75 39.5 47.25 55.0\n",
"blue 2.0 25.5 0.707107 25.0 25.25 25.5 25.75 26.0\n",
"pink 1.0 24.0 NaN 24.0 24.00 24.0 24.00 24.0\n",
"red 1.0 32.0 NaN 32.0 32.00 32.0 32.00 32.0"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"d.describe()"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"d.ngroups"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Age</th>\n",
" <th>Favourite Color</th>\n",
" <th>Name</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>24</td>\n",
" <td>black</td>\n",
" <td>Prashant</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>55</td>\n",
" <td>black</td>\n",
" <td>Murali</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Age Favourite Color Name\n",
"4 24 black Prashant\n",
"5 55 black Murali"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"d.get_group('black')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
%% Cell type:code id: tags:
``` python
import pandas as pd
```
%% Cell type:code id: tags:
``` python
records = [{'Name':'Ganesh', 'Age':27, 'Favourite Color': 'red'},
{'Name':'Bhanu', 'Age':21},
{'Name':'Vishalini', 'Age':20},
{'Name':'Ravali', 'Age':19, 'Favourite Color': 'pink'},
{'Name':'Prashant', 'Age':19, 'Favourite Color': 'black'},
{'Name':'Murali', 'Age':50, 'Favourite Color': 'black'}]
```</