0

I have a vector of dates of size 10 and type numpy.ndarray. I also have an array of temperatures at each hour of size 10x24.

I want to print the dates in column A and the corresponding temperature in columns B through Y for rows 1 though 10 in a csv file.

My arrays look as following:

print(AllDays)
[datetime.date(2008, 12, 31) datetime.date(2009, 1, 1)
 datetime.date(2009, 1, 2) ..., datetime.date(2015, 11, 28)
 datetime.date(2015, 11, 29) datetime.date(2015, 11, 30)]

So far I have to trying to implement this using dataframes as below:

TempDay   =   pd.DataFrame()
TempDay['Dates']  =   AllDays #of size 10
TempDay['Temperature'] = TemperatureArray #of size 10x24

If the previous step had worked I aimed at: TempDay.to_csv('C:\MyFile.csv')

But the above method has not been working.

1 Answer 1

2

It's not working because you trying to assign dataframe to column. You could construct pandas dataframe with your TemperatureArray and then add Dates column:

TempDay = pd.DataFrame(TemperatureArray)
TempDay['Dates'] = AllDays
TempDay.to_csv('C:\MyFile.csv')
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.