Last active
July 25, 2018 22:59
-
-
Save vinaykudari/da7216458b9af0c6b4ce723feaa59db5 to your computer and use it in GitHub Desktop.
Importing Data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Without Arguments" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 41, | |
"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>The following stock data was collect on 2016-AUG-25 from an unknown source</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>These kind of ocmments are not very useful</th>\n", | |
" <td>are they?</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>probably should just throw this line away too</th>\n", | |
" <td>but not the next since those are column labels</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>name Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec</th>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th># So that line you just read has all the column headers labels</th>\n", | |
" <td>NaN</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" The following stock data was collect on 2016-AUG-25 from an unknown source\n", | |
"These kind of ocmments are not very useful are they? \n", | |
"probably should just throw this line away too but not the next since those are column labels \n", | |
"name Jan Feb Mar Apr May Jun Jul Aug Sep Oct No... NaN \n", | |
"# So that line you just read has all the column... NaN " | |
] | |
}, | |
"execution_count": 41, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"df = pd.read_csv('messy_stock_data.tsv')\n", | |
"df.head(4)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# With Arguments" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 42, | |
"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>name</th>\n", | |
" <th>Jan</th>\n", | |
" <th>Feb</th>\n", | |
" <th>Mar</th>\n", | |
" <th>Apr</th>\n", | |
" <th>May</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>IBM</td>\n", | |
" <td>156.08</td>\n", | |
" <td>160.01</td>\n", | |
" <td>159.81</td>\n", | |
" <td>165.22</td>\n", | |
" <td>172.25</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>MSFT</td>\n", | |
" <td>45.51</td>\n", | |
" <td>43.08</td>\n", | |
" <td>42.13</td>\n", | |
" <td>43.47</td>\n", | |
" <td>47.53</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>GOOGLE</td>\n", | |
" <td>512.42</td>\n", | |
" <td>537.99</td>\n", | |
" <td>559.72</td>\n", | |
" <td>540.50</td>\n", | |
" <td>535.24</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>APPLE</td>\n", | |
" <td>110.64</td>\n", | |
" <td>125.43</td>\n", | |
" <td>125.97</td>\n", | |
" <td>127.29</td>\n", | |
" <td>128.76</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" name Jan Feb Mar Apr May\n", | |
"0 IBM 156.08 160.01 159.81 165.22 172.25\n", | |
"1 MSFT 45.51 43.08 42.13 43.47 47.53\n", | |
"2 GOOGLE 512.42 537.99 559.72 540.50 535.24\n", | |
"3 APPLE 110.64 125.43 125.97 127.29 128.76" | |
] | |
}, | |
"execution_count": 42, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"df = pd.read_csv('messy_stock_data.tsv', header=3, delimiter=' ', comment='#', index_col=False, usecols=[0,1,2,3,4,5])\n", | |
"df.head(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.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