User Tools

Site Tools


chapter5

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
chapter5 [2014-06-26 09:45]
miho_sera [5.3.1 Correlation and covariance]
chapter5 [2014-06-26 09:48]
miho_sera [5.2.6 Sort]
Line 307: Line 307:
   frame   frame
   frame.rank(axis=1) #​ rank in each row   frame.rank(axis=1) #​ rank in each row
-  ​+ 
 +{{:​rank.png|}}
 ==== 5.2.7 Duplicated index ==== ==== 5.2.7 Duplicated index ====
   obj = Series(range(5),​ index=['​a',​ '​a',​ '​b',​ '​b',​ '​c'​])   obj = Series(range(5),​ index=['​a',​ '​a',​ '​b',​ '​b',​ '​c'​])
Line 454: Line 455:
   frame2.reset_index() #​ turns indexes into columns and gives a new index   frame2.reset_index() #​ turns indexes into columns and gives a new index
  
-  ​+===== 5.6 Other pandas topics ===== 
 +==== 5.6.1 Integer indexing ==== 
 +  ser = Series(np.arange(3.)) 
 +  ser 
 +  ser[-1] # returns error: label '​-1'​ does not exist 
 +  ser2 = Series(np.arange(3.),​ index=['​a',​ '​b',​ '​c'​]) 
 +  ser2 
 +  ser2[-1] # returns the 1st element from the end  
 +  ser.ix[:​1] #​ '​1'​ is regarded as row label  
 +  ser2.ix[:​1] #​ '​1'​ is regarded as row number 
 + 
 +Forced reference using data position 
 +  ser3 = Series(np.arange(3.),​ index=[-5, 1, 3]) 
 +  ser3.iget_value(2) 
 +  frame = DataFrame(np.arange(6).reshape((3,​2)),​ index=[2, 0, 1]) 
 +  frame.irow(0) 
 + 
 +==== 5.6.2 Panel ==== 
 +  import pandas.io.data as web 
 +  pdata = pd.Panel(dict((stk,​ web.get_data_yahoo(stk,​ '​1/​1/​2009',​ '​6/​1/​2012'​)) 
 +  for stk in ['​AAPL',​ '​GOOGL',​ '​MSFT',​ '​DELL'​])) 
 +  pdata 
 +  pdata = pdata.swapaxes('​items',​ '​minor'​) 
 +  pdata['​Adj Close'​] 
 +  pdata.ix[:, '​6/​1/​2012',​ :] # all rows, date='​6/​1/​2012',​ all columns 
 +  pdata.ix['​Adj Close',​ '​5/​22/​2012':,​ :] 
 +  stacked = pdata.ix[:, '​5/​30/​2012':,​ :​].to_frame() 
 +  stacked 
 +  stacked.to_panel()
chapter5.txt · Last modified: 2014-06-26 09:48 by miho_sera