Skip to content

Instantly share code, notes, and snippets.

@PANDATD
Created December 29, 2020 06:28
Show Gist options
  • Select an option

  • Save PANDATD/a1dac6f0fa2f38bae74d71a1b0c32898 to your computer and use it in GitHub Desktop.

Select an option

Save PANDATD/a1dac6f0fa2f38bae74d71a1b0c32898 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd \n",
"# package is being imported "
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv('data.csv')\n",
"note = \"\"\"df is an dataframe and dataframe is nothing but rows and columns\n",
"pd.read_csv method reads the csv data from csv file\"\"\" \n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(88883, 85)"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.shape\n",
"# it returns the rows and coloumns , note : don't include () after the shape \n"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"#df.info() # it prints the overall info "
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
"people = {\n",
" 'name':['pandatd','vbg','d','kunal','ceo','mukesh'],\n",
" 'companay':['coddersclub','coddersclub','coddersclub','coddersclub','coddersclub','client'],\n",
" 'email':['pandatd@coddersclub.com','vbg@coddersclub.com','d.coddersclub.com','kunal@coddersclub.com','ceo@coddersclub.com','mueksh@client-coddersclub.com']\n",
"}\n",
"#print(\"This is Dict: \",people)\n",
"new_df = pd.DataFrame(people)#new dataframe is created using people Dict\n",
"#new_df"
]
},
{
"cell_type": "code",
"execution_count": 74,
"metadata": {
"collapsed": true
},
"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>name</th>\n",
" <th>companay</th>\n",
" <th>email</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>pandatd</td>\n",
" <td>coddersclub</td>\n",
" <td>pandatd@coddersclub.com</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>vbg</td>\n",
" <td>coddersclub</td>\n",
" <td>vbg@coddersclub.com</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>d</td>\n",
" <td>coddersclub</td>\n",
" <td>d.coddersclub.com</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>kunal</td>\n",
" <td>coddersclub</td>\n",
" <td>kunal@coddersclub.com</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>ceo</td>\n",
" <td>coddersclub</td>\n",
" <td>ceo@coddersclub.com</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>mukesh</td>\n",
" <td>client</td>\n",
" <td>mueksh@client-coddersclub.com</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" name companay email\n",
"0 pandatd coddersclub pandatd@coddersclub.com\n",
"1 vbg coddersclub vbg@coddersclub.com\n",
"2 d coddersclub d.coddersclub.com\n",
"3 kunal coddersclub kunal@coddersclub.com\n",
"4 ceo coddersclub ceo@coddersclub.com\n",
"5 mukesh client mueksh@client-coddersclub.com"
]
},
"execution_count": 74,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"new_df"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {
"collapsed": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"1) iloc is stands for integer location.\n",
"2) iloc only takes integer as location.\n",
" \n"
]
},
{
"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>name</th>\n",
" <th>companay</th>\n",
" <th>email</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>pandatd</td>\n",
" <td>coddersclub</td>\n",
" <td>pandatd@coddersclub.com</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>vbg</td>\n",
" <td>coddersclub</td>\n",
" <td>vbg@coddersclub.com</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" name companay email\n",
"0 pandatd coddersclub pandatd@coddersclub.com\n",
"1 vbg coddersclub vbg@coddersclub.com"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"note_iloc = \"\"\"\n",
"1) iloc is stands for integer location.\n",
"2) iloc only takes integer as location.\n",
" \"\"\"\n",
"print(note_iloc)\n",
"#new_df.iloc[0]# By using iloc we fetched the first index \n",
"# Not only we use integer but also a slicicing as we done in list or tuple.\n",
"# But hear's indexing is diff we can not use [] this brackes only we pass the vale like 0:2.\n",
"# let's take an exmple of slicing with iloc\n",
"new_df.iloc[:2]\n",
"# Above statment is an example of slicing "
]
},
{
"cell_type": "code",
"execution_count": 71,
"metadata": {
"collapsed": true
},
"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>name</th>\n",
" <th>companay</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>vbg</td>\n",
" <td>coddersclub</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>d</td>\n",
" <td>coddersclub</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" name companay\n",
"1 vbg coddersclub\n",
"2 d coddersclub"
]
},
"execution_count": 71,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Now we see loc \n",
"note_loc = \"\"\"\n",
" 1) loc is stands for location \n",
" \"\"\"\n",
"#new_df.columns # Feching the column names \n",
"new_df.loc[0:3:2, 'name':'companay']\n",
"# In above example we will fetched the data usinig loc method\n",
"# In above exmple we did the slicing \n",
"new_df.loc[[1,2],['name','companay']]\n",
"# In above the example we wiil fetched the 1,and second record assosiate to 'name' and 'company'."
]
},
{
"cell_type": "code",
"execution_count": 111,
"metadata": {
"collapsed": true
},
"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>name</th>\n",
" <th>email</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>pandatd</td>\n",
" <td>pandatd@coddersclub.com</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>vbg</td>\n",
" <td>vbg@coddersclub.com</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>d</td>\n",
" <td>d.coddersclub.com</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>kunal</td>\n",
" <td>kunal@coddersclub.com</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>ceo</td>\n",
" <td>ceo@coddersclub.com</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>mukesh</td>\n",
" <td>mueksh@client-coddersclub.com</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" name email\n",
"0 pandatd pandatd@coddersclub.com\n",
"1 vbg vbg@coddersclub.com\n",
"2 d d.coddersclub.com\n",
"3 kunal kunal@coddersclub.com\n",
"4 ceo ceo@coddersclub.com\n",
"5 mukesh mueksh@client-coddersclub.com"
]
},
"execution_count": 111,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"new_df[['name','email']]"
]
},
{
"cell_type": "code",
"execution_count": 159,
"metadata": {},
"outputs": [],
"source": [
"df.columns\n",
"def get_data(rowstart:int =0,rowend:int=5,\n",
" col1=0,col2=5)->object:\n",
" return df.iloc[rowstart:rowend, col1:col2]\n",
"\n",
"#get_data(rowstart=0,rowend=20,col1=2,col2=4)"
]
}
],
"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.9.1"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
@PANDATD
Copy link
Author

PANDATD commented Mar 17, 2021

making more improvement
I will be making more notebooks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment