<jupyter_start><jupyter_text>___ ___ ** Typically we will just be either reading csv files directly or using pandas-datareader or quandl. Consider this lecture just a quick overview of what is possible with pandas (we won't be working with SQL or excel files in this course) **  Data Input and OutputThis notebook is the reference code for getting input and output, pandas can read a variety of file types using its pd.read_ methods. Let's take a look at the most common data types:<jupyter_code>import numpy as np
import pandas as pd<jupyter_output><empty_output><jupyter_text>CSV CSV Input<jupyter_code>df = pd.read_csv('example')
df<jupyter_output><empty_output><jupyter_text>CSV Output<jupyter_code>df.to_csv('example',index=False)<jupyter_output><empty_output><jupyter_text>ExcelPandas can read and write excel files, keep in mind, this only imports data. Not formulas or images, having images or macros may cause this read_excel method to crash.   Excel Input<jupyter_code>pd.read_excel('Excel_Sample.xlsx',sheetname='Sheet1')<jupyter_output><empty_output><jupyter_text>Excel Output<jupyter_code>df.to_excel('Excel_Sample.xlsx',sheet_name='Sheet1')<jupyter_output><empty_output><jupyter_text>HTMLYou may need to install htmllib5,lxml, and BeautifulSoup4. In your terminal/command prompt run:    conda install lxml    conda install html5lib    conda install BeautifulSoup4Then restart Jupyter Notebook.(or use pip install if you aren't using the Anaconda Distribution)Pandas can read table tabs off of html. For example:  HTML InputPandas read_html function will read tables off of a webpage and return a list of DataFrame objects:<jupyter_code>df = pd.read_html('http://www.fdic.gov/bank/individual/failed/banklist.html')
df[0]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07487237663074305, 'fraction_numerical': 0.003970504821327283, 'mean_word_length': 6.770925110132159, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '232591', 'license': 'Apache-2.0', 'n_tokens_mistral': 566, 'n_tokens_neox': 541, 'n_words': 183, 'path': '03- General Pandas/.ipynb_checkpoints/08-Data-Input-and-Output-checkpoint.ipynb', 'repo_name': 'rikimarutsui/Python-for-Finance-Repo', 'size': '1763'}