0

I have a a DataFrame - ES_15M - that looks as follows:

[![ES_15M][1]][1]

Below is some sample data that I'm using:

Ticker Date/Time Close
ES H7 10/18/16 1:44 PM 2128
ES H7 10/18/16 1:59 PM 2128.75
ES H7 10/18/16 2:14 PM 2125.75
ES H7 10/18/16 2:29 PM 2126.5
ES H7 10/18/16 2:44 PM 2126.5
ES H7 10/18/16 4:14 PM 2126
ES H7 10/18/16 4:44 PM 2126.25
ES H7 10/18/16 5:59 PM 2126.5

I want to remake the DataFrame, basically just copy in its image as I'm going to merge this dataframe with another one (from another python file). The 'ES_15M' Dataframe comes from 'ES_LR_15M' Python file below. So:

import sys 
import os

sys.path.append(os.path.abspath(r"C:\Users\cost9\OneDrive\Documents\PYTHON\TEST-ASSURANCE FILES\LINEAR REGRESSION MULTI TREND IDENTIFICATION\LR\ES\STAGE 2"))

from ES_LR_1D import *
from ES_LR_1H import *
from ES_LR_15M import *

So after importing 'ES_15M' dataframe, I do the following:

ES_15M_Summary = ES_15M
ES_15M_Summary = pd.DataFrame(ES_15M_Summary)

The problem is, the dates go away on the new 'ES_15M_Summary:

     Ticker  Date     Open     High      Low    Close  Volume  Open Interest  \
0     ES H7     0  2128.25  2128.50  2128.00  2128.00      10              0   
1     ES H7     1  2127.75  2129.25  2127.75  2128.75       6              0   
2     ES H7     2  2127.25  2127.25  2124.50  2125.75      22              0   
3     ES H7     3  2126.50  2126.50  2126.50  2126.50       1              0   
4     ES H7     4  2125.75  2126.75  2125.75  2126.50       4              0   
5     ES H7     5  2126.25  2126.25  2126.00  2126.00       6              0   
6     ES H7     6  2126.50  2126.50  2126.25  2126.25       3              0   
7     ES H7     7  2126.50  2126.50  2126.50  2126.50       2              0   
8     ES H7     8  2127.00  2127.00  2127.00  2127.00       1              0   
9     ES H7     9  2126.50  2127.75  2126.50  2127.75       2              0   

I have to match these dates with the other dataframe I'll be merging on so this is a problem. How do I keep the dates when re-creating the dataframe?

edit: Okay here's a sample. I'm creating random AAPL stock price data and I need the same as above - to recreate the DataFrame:

stocks = pd.DataFrame({ 
    'ticker':np.repeat( ['aapl'], 25 ),
    'date':np.tile( pd.date_range('1/1/2011', periods=25, freq='D'), 1 ),
    'price':(np.random.randn(25).cumsum())})

        date     price ticker
0  2011-01-01 -1.642040   aapl
1  2011-01-02 -3.308491   aapl
2  2011-01-03 -4.843908   aapl
3  2011-01-04 -4.081345   aapl
4  2011-01-05 -3.356592   aapl
5  2011-01-06 -2.729077   aapl
6  2011-01-07 -2.011651   aapl
7  2011-01-08 -2.388161   aapl
8  2011-01-09 -1.198737   aapl
9  2011-01-10 -0.387553   aapl
10 2011-01-11  0.960245   aapl

When I re-create the DataFrame with the random price data here I get the same values as above, with dates still present rather than integers replacing them:

stocks2 = pd.DataFrame(stocks)

So I'm not sure what's wrong with my code in the original example.

Cole Starbuck
  • 603
  • 3
  • 11
  • 21
  • Please provide the input data so that we can experiment with it without retyping it from a screenshot. Have a look at [How to make a good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) for further information. – languitar Feb 22 '17 at 15:33
  • Alright, i updated it and got rid of screenshots – Cole Starbuck Feb 23 '17 at 14:29

0 Answers0