I understand that Pandas is designed to load a fully populated DataFrame
, but I need to create an empty DataFrame then add rows, one by one.
What is the best way to do this?
I successfully created an empty DataFrame with:
res = DataFrame(columns=('lib', 'qty1', 'qty2'))
Then I can add a new row and fill a field with:
res = res.set_value(len(res), 'qty1', 10.0)
It works, but it seems very odd :-/ (It fails for adding a string value.)
How can I add a new row to my DataFrame (with a different columns type)?
Best Answer
You can use
df.loc[i]
, where the row with indexi
will be what you specify it to be in the dataframe.