Differences between revisions 1 and 9 (spanning 8 versions)
Revision 1 as of 2013-08-30 04:07:31
Size: 460
Comment:
Revision 9 as of 2016-05-17 04:13:17
Size: 2204
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
Describe Pandas here.
Line 31: Line 29:

== Yahoo Finance ==
 *Read some quotes
{{{
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']
}}}
 * 28.09 - 26.74 ...looks like I would lose money

=== What was the low point and when was high point ===

{{{
price.columns
price.dtypes
price.head()
price.index
}}}
 *Now lets get to it
{{{
price.describe()

}}}
 *Looks like min was at 23.710000 and max was at 36.270000
 *Looks like lower 25% was at 26.572500 and most 75% were 31.165000 that means I should have made $5 per share if I was a long term investor
{{{
price.sort(column="Close").head(10)
price.sort(column="Close").tail(10)
}}}
 *Looks like I should have bought in 06/13/2011 and sell 07/16/2013

== 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 ==
 *http://synesthesiam.com/posts/an-introduction-to-pandas.html
 *https://gist.github.com/bsweger/e5817488d161f37dcbd2
 *http://wesmckinney.com/blog/filtering-out-duplicate-dataframe-rows/

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

  • Read some quotes

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']
  • 28.09 - 26.74 ...looks like I would lose money

What was the low point and when was high point

price.columns
price.dtypes
price.head()
price.index
  • Now lets get to it

price.describe()
  • Looks like min was at 23.710000 and max was at 36.270000
  • Looks like lower 25% was at 26.572500 and most 75% were 31.165000 that means I should have made $5 per share if I was a long term investor

price.sort(column="Close").head(10)
price.sort(column="Close").tail(10)
  • Looks like I should have bought in 06/13/2011 and sell 07/16/2013

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)