Back to Community
Python 101 DataFrame question.

I have done some research, but can't find (in a way that I can understand) how to create a simple object that has equities for columns and days of the week for rows.

My current feeble attempt is as follows;

    import pandas as pd  
    dailyHistoryOpen = history(context.DaysBackTest, '1d', 'open_price').dropna(axis = 1)  
    dailyHistoryClose =  history(context.DaysBackTest, '1d', 'close_price').dropna(axis = 1)  
    protoWeekDayCount = (history(1, '1d', 'open_price').dropna(axis = 1) - history(1, '1d', 'open_price').dropna(axis = 1))  
    weekDayUpCount = pd.DataFrame(protoWeekDayCount)  
    weekDayNeutralCount = pd.DataFrame(protoWeekDayCount)  
    weekDayDownCount = pd.DataFrame(protoWeekDayCount)  
    for indexDays, row in dailyHistoryOpen.iterrows():  
        currentDay = indexDays.to_datetime()  
        weekDay = currentDay.weekday()  
        for column in dailyHistoryOpen:  
            todaySignal = sign(dailyHistoryClose[column][indexDays] - dailyHistoryOpen[column][indexDays])  
            if todaySignal == 1:  
                if weekDay in weekDayUpCount[column].index :  
                    weekDayUpCount[column][weekDay] += 1  
                    dfWork = pd.DataFrame({column:1}, index=[0])  
            if todaySignal == 0:  
                if weekDay in weekDayNeutralCount[column].index :  
                    weekDayNeutralCount[column][weekDay] += 1  
                    dfWork = pd.DataFrame({column:1}, index=[0])  
            if todaySignal == -1:  
                if weekDay in weekDayDownCount[column].index :  
                    weekDayDownCount[column][weekDay] += 1  
                    dfWork = pd.DataFrame({column:1}, index=[0])  

It is late, and I will work on this on the morrow, if anyone can help I would appreciate it.

1 response

I forgot to press post until I woke up this morning. I guess I was tired.