I have a series called "template" that is 3600 $0.00's (one $0.00 for each second in the last hour, and indexed as such). I have another series called "transactions" that comes from data from an API request that is a variable number of non-zero dollar amounts, also indexed by timestamps. Since these transactions are all made within the last hour, all timestamps in "transactions" will be found in "template," but not vice versa (unless there was a transaction every second of the last hour).
For each timestamp in "template" that matches a timestamp in "transactions", I want to replace that $0.00 with the dollar amount in "transactions." I'm doing this to generate a plot of transactions in the last hour, hence the need for $0.00's instead of NaN's, and 3600 data points (to maintain the consistency of the time axis of the graph).
I thought for sure it was as simple as:
graphSeries = template.update(transactions)
but when I run
print(template)
print(transactions)
print(graphSeries)
I get this (the "None" at the end being the issue):
12-26-2021 21:30:39 0.0
12-26-2021 21:30:40 0.0
12-26-2021 21:30:41 0.0
12-26-2021 21:30:42 0.0
12-26-2021 21:30:43 0.0
...
12-26-2021 22:30:34 0.0
12-26-2021 22:30:35 0.0
12-26-2021 22:30:36 0.0
12-26-2021 22:30:37 0.0
12-26-2021 22:30:38 0.0
Length: 3600, dtype: float64
12-26-2021 21:31:10 697986.00
12-26-2021 21:32:07 8780106.00
12-26-2021 21:32:54 900542.00
12-26-2021 21:34:52 8784483.00
12-26-2021 21:35:05 26309692.00
12-26-2021 21:39:48 500000.00
12-26-2021 21:39:55 1999940.00
12-26-2021 21:41:54 1189745.40
12-26-2021 21:43:21 1399102.56
12-26-2021 21:44:33 1607717.00
12-26-2021 21:46:13 1189745.40
12-26-2021 21:47:56 1000000.00
12-26-2021 21:49:08 12414533.00
12-26-2021 21:50:21 1546034.00
12-26-2021 21:50:30 13141109.60
12-26-2021 21:50:33 2277359.00
12-26-2021 21:50:39 503834.00
12-26-2021 21:50:51 1397967.00
12-26-2021 21:51:03 580000.00
12-26-2021 21:51:44 542158.00
12-26-2021 21:52:12 1546034.00
12-26-2021 21:54:04 1662123.80
12-26-2021 21:54:31 12052320.00
12-26-2021 21:54:52 1546024.00
12-26-2021 21:55:53 1000000.00
12-26-2021 21:56:30 1507000.00
dtype: float64
None
Am I doing something wrong? Does pandas' update(Series) method not index with timestamps?
CodePudding user response:
Update is an inplace function, try:
template.update(transactions)
print(template)
More info on update
: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.update.html