I have a DataFrame that is resampled into a smaller DataFrame, which retained a datetimeindex. I transposed the dataframe and now wish to remove the dateindex and replace it with strings (labels), then export it to .csv to be used in a format that can be read by javascript (doing all data manipulation in python).
I did try to write it to a .csv without header (removing the date) and then reading it again to add the labels, but that doesn't seem very efficient.
Link to csv: https://www.dropbox.com/s/qy72yht2m7lk2pg/17_predicted.csv
Python/pandas Code:
import pandas as pd
import numpy as np
from dateutil.parser import parse
from datetime import datetime
from pandas import *
# Load csv into pandas DataFrame
df = pd.read_csv("17_predicted_dummydata.csv", parse_dates=True, dayfirst=False, keep_date_col=True, index_col=0)
#Creating a date range
df.index = pd.to_datetime(pd.date_range(start='1/1/2000 00:30:00', end='1/1/2000 05:00:00', freq='30T'))
#Rename index
df.index.name = 'date'
df_year = df.resample('D', how='sum')
df_year = np.round(df_year, 0)
df_year.index.name = 'label'
df_year.column = ['value']
df_year = df_year.T
print df_year.head()
print df_year.index.name
df_year.to_csv("17_dummy.csv") #drop index through header=False
CSV input:
Date/Time,InteriorEquipment:Electricity:Zone:4419 [J](TimeStep),InteriorEquipment:Electricity:Zone:3967 [J](TimeStep),InteriorEquipment:Electricity:Zone:3993 [J](TimeStep)
01/01 00:30:00,0.583979872,0.428071889,0.044676234
01/01 01:00:00,0.583979872,0.428071889,0.044676234
01/01 01:30:00,0.583979872,0.428071889,0.044676234
01/01 02:00:00,0.583979872,0.428071889,0.044676234
01/01 02:30:00,0.583979872,0.428071889,0.044676234
01/01 03:00:00,0.583979872,0.428071889,0.044676234
01/01 03:30:00,0.583979872,0.428071889,0.044676234
01/01 04:00:00,0.583979872,0.428071889,0.044676234
01/01 04:30:00,0.583979872,0.428071889,0.044676234
01/01 05:00:00,0.583979872,0.428071889,0.044676234
Proposed csv output:
label,value
InteriorEquipment:Electricity:Zone:4419 [J](TimeStep),6.0
InteriorEquipment:Electricity:Zone:3967 [J](TimeStep),4.0
InteriorEquipment:Electricity:Zone:3993 [J](TimeStep),0.0
I tried to follow this (Insert a row to pandas dataframe) workaround, but couldn't make it work.
Any help is appreciated!