aptitude install python-dev

pip install pandas
pip install MySQL-python

mysql_cn= MySQLdb.connect(host='localhost',user='myusername',passwd='mypassword',db='mydatabase') 

s=sql.read_frame("select * from recall_db;",mysql_cn)

Get some data

s
s.columns
s['MAKETXT']
s['MAKETXT'][:30]
s[s.MAKETXT=='FORD']
s.MAKETXT.value_counts()
s.YEARTXT.value_counts()
s.iloc[3]

Yahoo Finance

from pandas.io.data import DataReader
from datetime import datetime
from pandas.io.data import get_quote_yahoo, _yahoo_codes
_yahoo_codes.update({'MarketCap' : 'j1'})
_yahoo_codes.update({'52WeekLow' : 'j'})
_yahoo_codes.update({'DividentYeld' : 'y'})
_yahoo_codes.update({'52WeekRange' : 'w'})
_yahoo_codes.update({'DividentPerShare' : 'd'})
_yahoo_codes.update({'EarningsPerShare' : 'e'})
_yahoo_codes.update({'SharesOwned' : 's1'})
_yahoo_codes.update({'peg' : 'r5'})
print get_quote_yahoo("MSFT")

What if I bought this stock in 2011

price=DataReader("MSFT","yahoo",datetime(2011,1,1))
print price.ix['2011-01-04']
print price.ix['2013-01-04']

What was the low point and when was high point

price.columns
price.dtypes
price.head()
price.index

price.describe()

price.sort(column="Close").head(10)
price.sort(column="Close").tail(10)

read csv

import pandas
data=pandas.read_csv("08wmi.csv")
data
len(data)
data.make.unique()
data.wmi.unique()
data[['make','wmi']].groupby(['make','wmi']).size()


a=data[['wmi','make']].drop_duplicates()

Reference

MyWiki: Pandas (last edited 2016-05-17 04:13:17 by LukaszSzybalski)