Skip to content

Instantly share code, notes, and snippets.

@fomightez
Last active October 15, 2024 15:31
Show Gist options
  • Save fomightez/cd4b8a3e4e7a74bcd01b6519115ede2c to your computer and use it in GitHub Desktop.
Save fomightez/cd4b8a3e4e7a74bcd01b6519115ede2c to your computer and use it in GitHub Desktop.
Pandas example for Jupyter Discourse exchange

Pandas example for Jupyter Discourse exchange Using JupyterLab 4.3 with Python 3.11 on Binder

Binder

Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "3196982b-4e5b-4bea-9268-d7098c0f846e",
"metadata": {},
"source": [
"### Pandas example demo\n",
"\n",
"In regards to [Probleme Reading csv column , even its correct name coulmn i make in script](https://discourse.jupyter.org/t/probleme-reading-csv-column-even-its-correct-name-coulmn-i-make-in-script/29243?u=fomightez)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "8bdf2fdf-915e-4d7e-8897-7ef553db90fb",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"mutual_funds = pd.DataFrame({'A': range(1, 6),\n",
" 'B': range(10, 0, -2),\n",
" 'Investment_Return': range(100, 0, -20),\n",
" 'C C': range(10, 5, -1)})"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "a3685664-c7f2-431f-b66a-acbf85e88104",
"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>A</th>\n",
" <th>B</th>\n",
" <th>Investment_Return</th>\n",
" <th>C C</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>10</td>\n",
" <td>100</td>\n",
" <td>10</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2</td>\n",
" <td>8</td>\n",
" <td>80</td>\n",
" <td>9</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>3</td>\n",
" <td>6</td>\n",
" <td>60</td>\n",
" <td>8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>40</td>\n",
" <td>7</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>5</td>\n",
" <td>2</td>\n",
" <td>20</td>\n",
" <td>6</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" A B Investment_Return C C\n",
"0 1 10 100 10\n",
"1 2 8 80 9\n",
"2 3 6 60 8\n",
"3 4 4 40 7\n",
"4 5 2 20 6"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mutual_funds"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "52135ec1-bd06-4c38-8851-0ba9ed8248bc",
"metadata": {},
"outputs": [],
"source": [
"good_return_threshold = 51\n",
"def classify_return(Investment_Return):\n",
" if Investment_Return> good_return_threshold:\n",
" return 'Good'\n",
" else:\n",
" return 'Not good'\n",
"mutual_funds['Return_Classification']= mutual_funds['Investment_Return'].apply(classify_return)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "95111d3b-2282-40ad-8918-779b7edf147e",
"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>A</th>\n",
" <th>B</th>\n",
" <th>Investment_Return</th>\n",
" <th>C C</th>\n",
" <th>Return_Classification</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>10</td>\n",
" <td>100</td>\n",
" <td>10</td>\n",
" <td>Good</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2</td>\n",
" <td>8</td>\n",
" <td>80</td>\n",
" <td>9</td>\n",
" <td>Good</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>3</td>\n",
" <td>6</td>\n",
" <td>60</td>\n",
" <td>8</td>\n",
" <td>Good</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>40</td>\n",
" <td>7</td>\n",
" <td>Not good</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>5</td>\n",
" <td>2</td>\n",
" <td>20</td>\n",
" <td>6</td>\n",
" <td>Not good</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" A B Investment_Return C C Return_Classification\n",
"0 1 10 100 10 Good\n",
"1 2 8 80 9 Good\n",
"2 3 6 60 8 Good\n",
"3 4 4 40 7 Not good\n",
"4 5 2 20 6 Not good"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mutual_funds"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9e26d781-ceff-422d-87d4-1eea9238edf8",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
jupyterlab>=4.3.0b1
pandas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment