Skip to content

Instantly share code, notes, and snippets.

@aateg
Created June 1, 2019 17:00
Show Gist options
  • Save aateg/47202b8fac1ef1ea587b178d4faaa7bb to your computer and use it in GitHub Desktop.
Save aateg/47202b8fac1ef1ea587b178d4faaa7bb 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",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 3,
"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>C</th>\n",
" <th>D</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.616149</td>\n",
" <td>0.821017</td>\n",
" <td>0.150830</td>\n",
" <td>0.538643</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0.599560</td>\n",
" <td>0.893655</td>\n",
" <td>0.622565</td>\n",
" <td>0.914114</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0.581489</td>\n",
" <td>0.521830</td>\n",
" <td>0.829649</td>\n",
" <td>0.323176</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0.783207</td>\n",
" <td>0.846791</td>\n",
" <td>0.013040</td>\n",
" <td>0.582965</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" A B C D\n",
"0 0.616149 0.821017 0.150830 0.538643\n",
"1 0.599560 0.893655 0.622565 0.914114\n",
"2 0.581489 0.521830 0.829649 0.323176\n",
"3 0.783207 0.846791 0.013040 0.582965"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# criando dataframe a partir de numpy array\n",
"df = pd.DataFrame(np.random.random((4,4)),columns=list('ABCD'))\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 4,
"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>C</th>\n",
" <th>D</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1.0</td>\n",
" <td>2019-01-01</td>\n",
" <td>foo</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1.0</td>\n",
" <td>2019-01-01</td>\n",
" <td>foo</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>1.0</td>\n",
" <td>2019-01-01</td>\n",
" <td>foo</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>1.0</td>\n",
" <td>2019-01-01</td>\n",
" <td>foo</td>\n",
" <td>4</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" A B C D\n",
"0 1.0 2019-01-01 foo 1\n",
"1 1.0 2019-01-01 foo 2\n",
"2 1.0 2019-01-01 foo 3\n",
"3 1.0 2019-01-01 foo 4"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# criando dataframe a partir de dicionário\n",
"df2 = pd.DataFrame({\n",
" 'A': 1.,\n",
" 'B': pd.Timestamp('20190101'),\n",
" 'C': 'foo',\n",
" 'D': np.array([1,2,3,4])\n",
"})\n",
"df2"
]
}
],
"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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment