Suppose that I create the following df:
import pandas as pd
#column names
column_names = ["Time", "Currency", "Volatility expected", "Event", "Actual", "Forecast", "Previous"]
#create a dataframe including the column names
df = pd.DataFrame(columns=column_names)
Then, I create the following array that will have the cell values to add to my df
:
rows = ["2:00", "GBP", "", "Construction Output (MoM) (Jan)", "1.1%", "0.5%", "2.0%",
"2:00", "GBP", "", "U.K. Construction Output (YoY) (Jan)", "9.9%", "9.2%", "7.4%"]
So, how can I use a for loop to update my df
so it ends up like this:
|Time |Currency |Volatility expected |Event |Actual |Forecast |Previous |
------------------------------------------------------------------------------------------------------------------
|02:00 |GBP | |Construction Output (MoM) (Jan) |1.1% |0.5% |2.0% |
|04:00 |GBP | |U.K. Construction Output (YoY) (Jan)|9.9% |9.2% |7.4% |
I tried:
column_name_location = 0
for row in rows:
df.at['0', df[column_name_location]] = row
column_name_location += 1
print(df)
But got:
KeyError: 0
May I get some advice here?