I have a dataframe which contains an aggregated value till today. My datastream will update everyday so that I want to monitoring the change of each day. How can I append each newday's data to the dataframe?
The format will be like this,
Date Agg_Value
2022-12-07 0.43
2022-12-08 0.44
2022-12-09 0.41
... ...
CodePudding user response:
You want to use pandas.concat to bring together 2 dataframes:
import pandas as pd
s1 = pd.Series(['a', 'b'])
s2 = pd.Series(['c', 'd'])
print(pd.concat([s1, s2]))
CodePudding user response:
Assuming that you always have yesterday's dataframe available, you can simply execute a script that runs everyday to get today's date and concatenate the result.
# Assuming you have todays value
today_value = 42
# Get today's date
from datetime import date
today = date.today()
# Create a new dataframe with today's value
df1 = pd.DataFrame(
{
'Date':[str(today)],
'Agg_value':[today_value]
}
)
# Update df by concatenating today's data
df = pd.concat([df, df1], axis=0)