User Tools

Site Tools


data:pandas:allign

Differences

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

Link to this comparison view

Next revision
Previous revision
data:pandas:allign [2018/03/24 13:15] – created aistisdata:pandas:allign [2018/04/03 20:45] (current) – aistis
Line 1: Line 1:
-you can join objects if they have same type axis+allign data in DataFrame 
 +<code python> 
 +#allign data to dataframe 
 +df1 = pd.DataFrame(0.0, index=all_date, columns=[a.sidb for a in d]) 
 +start = time.time() 
 +for q in d: 
 +    df1.iloc[np.in1d(all_date, q.date, assume_unique=True),  
 +       df1.columns.get_loc(q.sidb)] = q.pnl 
 +print ("Result: %.2f secs" % (time.time() - start)) 
 +</code> 
 + 
 + 
 +allign data in numpy array (3x faster) 
 +<code python> 
 +# allign using numpy 
 +start = time.time() 
 +a1 = np.zeros((len(d), len(all_date))) 
 +i = 0 
 +for q in d: 
 +    idx = np.in1d(all_date, q.date, assume_unique=True) 
 +    a1[i, idx] = q.pnl 
 +    i = i + 1 
 +print ("Result: %.2f secs" % (time.time() - start)) 
 +</code> 
 + 
 + 
 + 
 +you can join/merge objects if they have same type axis 
 + 
 +for example align two time series by date
  
 {{:data:pandas:pasted:20180324-131514.png}} {{:data:pandas:pasted:20180324-131514.png}}
 +
 +{{:data:pandas:pasted:20180324-132455.png}}
data/pandas/allign.1521890115.txt.gz · Last modified: by aistis