Skip to content

Instantly share code, notes, and snippets.

@snippsat
Created June 28, 2019 11:54
Show Gist options
  • Save snippsat/b042d12ada459f3a47644ce86b2069f5 to your computer and use it in GitHub Desktop.
Save snippsat/b042d12ada459f3a47644ce86b2069f5 to your computer and use it in GitHub Desktop.
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
"data = {\n",
" \"country\": [\"Brazil\", \"Russia\", \"India\", \"China\", \"South Africa\"],\n",
" \"capital\": [\"Brasilia\", \"Moscow\", \"New Dehli\", \"Beijing\", \"Pretoria\"],\n",
" \"area\": [8.516, 17.10, 3.286, 9.597, 1.221],\n",
" \"population\": [200.4, 143.5, 1252, 1357, 52.98],\n",
"}\n",
"\n",
"df = pd.DataFrame(data)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"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>country</th>\n",
" <th>capital</th>\n",
" <th>area</th>\n",
" <th>population</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Brazil</td>\n",
" <td>Brasilia</td>\n",
" <td>8.516</td>\n",
" <td>200.40</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Russia</td>\n",
" <td>Moscow</td>\n",
" <td>17.100</td>\n",
" <td>143.50</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>India</td>\n",
" <td>New Dehli</td>\n",
" <td>3.286</td>\n",
" <td>1252.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>China</td>\n",
" <td>Beijing</td>\n",
" <td>9.597</td>\n",
" <td>1357.00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>South Africa</td>\n",
" <td>Pretoria</td>\n",
" <td>1.221</td>\n",
" <td>52.98</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" country capital area population\n",
"0 Brazil Brasilia 8.516 200.40\n",
"1 Russia Moscow 17.100 143.50\n",
"2 India New Dehli 3.286 1252.00\n",
"3 China Beijing 9.597 1357.00\n",
"4 South Africa Pretoria 1.221 52.98"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th>country</th>\n",
" <th>capital</th>\n",
" <th>area</th>\n",
" <th>population</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>Brazil</td>\n",
" <td>Brasilia</td>\n",
" <td>8.516</td>\n",
" <td>200.40</td>\n",
" </tr>\n",
" <tr>\n",
" <td>Russia</td>\n",
" <td>Moscow</td>\n",
" <td>17.100</td>\n",
" <td>143.50</td>\n",
" </tr>\n",
" <tr>\n",
" <td>India</td>\n",
" <td>New Dehli</td>\n",
" <td>3.286</td>\n",
" <td>1252.00</td>\n",
" </tr>\n",
" <tr>\n",
" <td>China</td>\n",
" <td>Beijing</td>\n",
" <td>9.597</td>\n",
" <td>1357.00</td>\n",
" </tr>\n",
" <tr>\n",
" <td>South Africa</td>\n",
" <td>Pretoria</td>\n",
" <td>1.221</td>\n",
" <td>52.98</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n"
]
}
],
"source": [
"table = df.to_html(index=False)\n",
"print(table)"
]
}
],
"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.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment