I would like to copy certain column values from a specific row in my dataframe df to another dataframe called bestdf
Here I create an empty dataframe (called bestdf):
new_columns = ['DATE', 'PRICE1', 'PRICE2']
bestdf = pd.DataFrame(columns = new_columns)
bestdf.set_index(['DATE'])
.I've located a certain row out of df and assigned the row to a variable last_time:
last_time = df.iloc[-1]
print last_time
gives me
DATETIME PRC
2016-10-03 00:07:39.295000 335.82
I then want to take the 2016-10-03 from the DATETIME column and put that into the DATE column of my other dataframe (bestdf).
I also want to take the PRC and put it into the PRICE1 column of my empty dataframe. I want bestdf to look like this:
DATE PRICE1 PRICE2
2016-10-03 335.82
Here is what I've got so far?
sample_date = str(last_time).split()
best_price = sample_date[2]
sample_date = sample_date[0]
bestdf['DATE'] = sample_date
bestdf['PRICE1'] = best_price
This doesn't seem to work though. FYI I also want to put this into a loop (where last_time will be amended and each time the new values will be written to a new row). I'm just currently trying to get the functionality correct.
Please help!
Thanks