Solved

Datapoints - Retrieve as pandas dataframe

  • 15 August 2023
  • 2 replies
  • 74 views

Badge +2

I want to retrieve data frame based on external IDs for the past 24 hours. So, if current date = 08/15/2023, it should try to get the previous day’s datapoints for 24 hours i.e, from 08/14/2023 00:00:00 to 08/14/2023 23:59:59. 

Please share with the actual code on how to put the parameters. 

 

from cognite.client import CogniteClient
client = CogniteClient()
df = client.time_series.data.retrieve_dataframe(
... id=12345,
... start=<What to fill here>,
... end=<what to fill here>)

 

icon

Best answer by HaydenH 15 August 2023, 19:41

View original

2 replies

Hello @eashwar11. There are some nice examples in the docs here. As you can see, if end is not specified in the arguments, it will default to the current time. So you can leave the end parameter as is, and then specify the string “1d-ago” for start, and that will query for 1 day previous to now. However, if you always want it to be starting at 00:00 from the previous day, then you would simply do some datetime arithmetic. Something like:

end = datetime.now().date()

start = end - timedelta(days=1)

would work. Hope that helps! 😀

Userlevel 4
Badge +2

Hi @eashwar11,

We are following up to see whether you're satisfied with the responses you've received?

If you found the responses offered by our community members to be instructive and helpful, we kindly request that you consider marking the most helpful response as the "Best Answer."This little action will acknowledges the person who offered the answer and also makes it simpler for other community members to find the most correct comments.

Best regards,
Dilini

 

Reply