I want to create an empty DataFrame
where I will append others single row DataFrame
with new data. I am trying to use panda's "Setting With Enlargement" for efficient appending.
import numpy as np
import pandas as pd
from datetime import datetime
from pandas import DataFrame
df = DataFrame(columns=["open","high","low","close","volume","open_interest"])
row_one = DataFrame({"open":10,"high":11,"low":9,"close":10,"volume":100,"open_interest":np.NAN}, index = [datetime(2017,1,1)])
row_two = DataFrame({"open":9,"high":12,"low":8,"close":10.50,"volume":500,"open_interest":np.NAN}, index = [datetime(2017,1,2)])
Now, when I try to append the new row following the setting with enlargement rules:
df[row_one.index] = row_one.columns
I get this error:
"DatetimeIndex(['2017-01-01'], dtype='datetime64[ns]', freq=None) not in index"
I thought the row should be automatically added because it is not in the DataFrame
. What am I doing wrong?