Interfacing with Spreadsheets

# -*- coding: utf-8 -*-
"""
Created on Sun Jan  5 11:02:36 2020

@author: Bruce1
"""

# =======================================================================
# Import Pandas Library
# =======================================================================
import pandas as pd 

# =======================================================================
# Read in CSV File - Data Frame
# =======================================================================
df = pd.read_csv('AAPL.csv')
df = pd.read_csv('AAPL.csv', parse_dates=True, index_col=0)

# =======================================================================
# Examine DataFrame
# =======================================================================
print ( df.head() )
print ( df.tail(3) )
print ( df.Date.head() )
print ( df[['Date','Open']].head() )
print ( df.columns )

# =======================================================================
# Manipulation of Data - SMA
# =======================================================================
df.loc[:,'3d-SMA'] = df['Adj Close'].rolling(window=3).mean()
print ( df[['Adj Close','3d-SMA']].head() )
print ( df[['Adj Close','3d-SMA']].tail() )

# =======================================================================
# Output Data
# =======================================================================
df.to_csv('AAPL_python.csv')
df.to_excel("AAPL_python.xlsx")