Error encountered when attempting to resample time series data using Python's pandas module

I have a dataset with time-series data in the following format:

              ticker        close
created_at                                   
2020-06-10 18:30:00+00:00   TSLA  1017.419312
2020-06-10 17:02:00+00:00   TSLA  1014.354980
2020-06-10 17:03:00+00:00   TSLA  1014.922302
2020-06-10 17:04:00+00:00   TSLA  1015.626709
2020-06-10 17:05:00+00:00   TSLA  1016.400024
2020-06-10 17:06:00+00:00   TSLA  1017.223389
2020-06-10 17:07:00+00:00   TSLA  1016.110107
2020-06-10 17:08:00+00:00   TSLA  1016.109985
..........................................

I am attempting to resample the data using a 5-minute interval, and here is my code snippet:

df = pd.read_sql_query("SELECT created_at,ticker,close FROM market_data_history WHERE ticker='TSLA' and CREATED_AT > '2020-06-10 00:01:00+00' AND created_at < '2020-06-11 00:01:00+00'", index_col='created_at', con=engine)
# df = pd.read_csv("market_data_history.csv", usecols = ['created_at','ticker','close','volume'])
print(df)

d=df.resample('5T')
print(d)

Unfortunately, when I run this code, the output only displays:

DatetimeIndexResampler [freq=<5 * Minutes>, axis=0, closed=left, label=left, convention=start, base=0]

I'm puzzled as to why the resampling isn't being applied. Can someone please provide assistance?

Answer №1

resample acts like a group-by function where you specify how to aggregate resampled data.

For instance:

df.resample("5T").max()

will result in:

                          symbol        value
created_at                                   
2020-06-10 17:00:00+00:00   AAPL  212.426555
2020-06-10 17:05:00+00:00   AAPL  213.357254
2020-06-10 17:10:00+00:00    NaN          NaN
2020-06-10 17:15:00+00:00    NaN          NaN
2020-06-10 17:20:00+00:00    NaN          NaN
2020-06-10 17:25:00+00:00    NaN          NaN
...

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Calculate Total Expenses using Python

Problem: The cost of a cupcake is represented as A dollars and B cents. Calculate the total amount in dollars and cents that should be paid for N cupcakes. The program requires three inputs: A, B, N. It will output two numbers representing the total cost. ...

Using Pydantic to define models with both fixed and additional fields based on a Dict[str, OtherModel], mirroring the TypeScript [key: string] approach

Referencing a similar question, the objective is to construct a TypeScript interface that resembles the following: interface ExpandedModel { fixed: number; [key: string]: OtherModel; } However, it is necessary to validate the OtherModel, so using the ...

What is the reason that a combination of two types in a list does not result in a list of combinations of these two types?

I encountered some difficulties with using mypy in scenarios where List and Union types are combined. Although I have found the solution, I wanted to share my discoveries here. The core question that arose was: why does a list of a union of two types not ...

What seems to be the issue with this json.load function call?

I wrote the following Python 3 code snippet: import json with open('calldb.json', 'r') as G: data = json.load(G) print(data) Accompanied by this JSON file: [ { "n": { "identity": 0, "labels": [ ...

I'm encountering a problem while attempting to upload an image in tkinter using a label

Whenever I attempt to upload an image using tkinter, I encounter an error. I have fetched a gif image and stored it in a file named "image.gif", and saved the picture as "image". #Displaying image using label logo = PhotoImage(file="img.gif") w1 = Label(n ...

Unable to pass the Selenium driver as an argument to a function when utilizing `pool.starmap`

I am encountering an issue where I cannot pass a Selenium driver as an argument to a function using pool.starmap. Below is a simplified example to reproduce and verify the problem: Main code: from wait import sleep import multiprocessing from selenium im ...

Retrieving the text value from a specialized attribute

I have a custom attribute named upgrade-test="secondary-pull mktg-data-content in the snippet of code below: <section class="dvd-pull tech-pull-- secondary-pull--anonymous tech-pull--digital secondary-pull--dvd-ping tech-pull--minimise" u ...

Load user information for the current logged in user using Django

Greetings fellow Django beginners! I know this question has been asked before, but I'm having trouble finding a solution that fits my specific situation. Here's the issue: I have a Form with a choice field that gets its options from the databas ...

Selenium Python: Navigating to Links with Hidden Text

I am attempting to click on all the links within a web page after selecting certain dates (), but unfortunately, the links do not have unique class names and only contain the tag name "a". There are multiple other elements with the same tag name which make ...

Using Python to extract all the links on a dynamic webpage

I am struggling to develop a universal crawler that can analyze a webpage and compile a list of all links within it, with the goal of examining an entire domain and all its internal links. I have attempted using HtmlUnit in Java and Selenium in Python, bu ...

Ways to eliminate tuples from a tuple list?

As I contemplate the cards in my hand, a sense of disappointment washes over me, urging me to abandon them and draw new ones. But how does one go about achieving this task? I find myself unable to dispose of these troublesome tuples - removing them with d ...

I'm having trouble adding a background image, even though I have set it to static. What could be

I attempted to add a background image to my Django website, but unfortunately, it was not successful. I followed the steps provided in this Stack Overflow answer here, however, it did not work. I even made changes to the database by migrating them, but s ...

The string is having difficulty being formatted with html characters

Looking for a solution to resolve the error I am encountering with my code: """<div id="spc-preview-edit-submit" class="spc-form"> <form action="{% url new-submission itemtype='%s' %}" ... ... </div></form> ...

Automating the process of navigating through pagination links using Selenium WebDriver's sets

I am new to using Selenium and I encountered a unique situation while scraping a website (page). The website does not have a traditional next page button for pagination. Instead, the pages change only when you click on the "..." option to reveal the next s ...

What is the procedure for configuring the x-axis to represent a timeline in a plotly icicle graph?

Looking to create an innovative icicle chart where the x-axis reflects a timeline rather than traditional categories. Check out this sample plotly icicle for reference: https://i.stack.imgur.com/0Hfwp.png My goal is to preserve the hierarchical layout wh ...

Steps to execute an external Python script in Django by clicking a dropdown button in the HTML

I am trying to set up a Django+Python frontend button that can trigger a Jenkins job. I have created a header with HTML containing a dropdown button. After researching various resources, it seems like AJAX is the way to go for triggering the Jenkins job. C ...

The problem with importing a pre-defined Selenium function in the browser

Initial Set-up Working with selenium, I found myself constantly redefining functions. To streamline the process, I decided to create a separate file for these functions and import them as needed in my work files. A Basic Example Initially, when all fun ...

Pyinstaller error: File cannot be found at 'C:\Users\my.name\Desktop\EPE 2.0\dist\main\timezonefinder\timezone_names.json'. It seems to be missing

Whenever I attempt to run my executable file generated by pyinstaller (using the latest version, Python v3.6 in an Anaconda environment), I encounter the following error: File "site-packages\timezonefinder\timezonefinder.py", line 27, in <mod ...

Converting a DataFrame into a dictionary in Python

I am attempting to recreate a bokeh bar chart with nested categories that is shown on this page: Starting with the dataframe below test__df = pd.DataFrame(data= [['2019-01-01','A',1], ['2019-01-01 ...

Tips for enhancing the parsing of arbitrary song lists

Interested in parsing tracklistings found in various formats, with lines like: artist - title artist-title artist / title artist - "title" 1. artist - title 0:00 - artist - tit le 05 artist - title 12:20 artist - title [record label] These text files ...