User Tools

Site Tools


data:pandas:allign

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
data:pandas:allign [2018/03/24 13:25] – aistisdata:pandas:allign [2018/04/03 20:45] (current) – aistis
Line 1: Line 1:
 +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 you can join/merge objects if they have same type axis
  
data/pandas/allign.1521890717.txt.gz · Last modified: by aistis