1

I am running a for loop for each of 12 months. For each month I get bunch of dates in random order over various years in history. I also have corresponding temperature data on those dates. e.g. if I am in month January, of loop all dates and temperature I get from history are for January only.

I want to start with empty pandas dataframe with two columns namely 'Dates' and 'Temperature'. As the loop progresses I want to add the dates from another month and corresponding data to the 'Temperature' column.

After my dataframe is ready I want to finally use the 'Dates'column as index to order the 'Temperature' history available so that I have correct historical sorted dates with their temperatures.

I have thought about using numpy array and storing dates and data in two separate arrays; sort the dates and then sort the temperature using some kind of index. I believe using pandas pivot table feature it will be better implemented in pandas.

1 Answer 1

1

@Zanam Pls refer this syntax. I think your question is similar to this answer

 df = DataFrame(columns=('lib', 'qty1', 'qty2'))
 for i in range(5):
    df.loc[i] = [randint(-1,1) for n in range(3)]

 print(df)

     lib  qty1  qty2
 0    0     0    -1
 1   -1    -1     1
 2    1    -1     1
 3    0     0     0
 4    1    -1    -1

 [5 rows x 3 columns]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.