Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8224717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:10:04+00:00 2026-06-07T15:10:04+00:00

I have a Python function historical_data that pulls daily historical price and dividend data

  • 0

I have a Python function historical_data that pulls daily historical price and dividend data from Yahoo Finance and outputs it into a pandas DataFrame.

>>> nlsn = y.historical_data('NLSN')
>>> nlsn
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 366 entries, 2012-07-10 00:00:00 to 2011-01-27 00:00:00
Data columns:
Open         366  non-null values
High         366  non-null values
Low          366  non-null values
Close        366  non-null values
Volume       366  non-null values
Adj Close    366  non-null values
Dividends    366  non-null values
dtypes: float64(6), int64(1)
>>> nlsn['Adj Close']
Date
2012-07-10    26.77
2012-07-09    26.77
2012-07-06    26.64
2012-07-05    26.56
2012-07-03    26.57
...
2011-02-01    25.75
2011-01-31    26.07
2011-01-28    25.00
2011-01-27    25.40
Name: Adj Close, Length: 366

I only want to store daily data persistently (vs. having to store daily, monthly, weekly, etc.). The following daily-to-monthly conversion doesn’t seem to work, though:

>>> nlsn['Adj Close'].asfreq('M', method='bfill')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/michael/Projects/envs/fintools32/lib/python3.2/site-packages/pandas/core/generic.py", line 156, in asfreq
    return asfreq(self, freq, method=method, how=how)
  File "/home/michael/Projects/envs/fintools32/lib/python3.2/site-packages/pandas/tseries/resample.py", line 329, in asfreq
    return obj.reindex(dti, method=method)
  File "/home/michael/Projects/envs/fintools32/lib/python3.2/site-packages/pandas/core/series.py", line 2053, in reindex
    level=level, limit=limit)
  File "/home/michael/Projects/envs/fintools32/lib/python3.2/site-packages/pandas/core/index.py", line 791, in reindex
    limit=limit)
  File "/home/michael/Projects/envs/fintools32/lib/python3.2/site-packages/pandas/core/index.py", line 719, in get_indexer
    assert(self.is_monotonic)
AssertionError

What’s the right way for me to aggregate these stock prices into Monthly?

What I’ve tried

I tried all different method arguments (ffill, pad, bfill), all of which seem to raise the same assertion error.

I tried checking the source code index.py, but there seems to be a Strategy pattern in effect where the class in question delegates is_monotonic to its _engine attribute, and I can’t find where the _engine attribute is actually assigned.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T15:10:05+00:00Added an answer on June 7, 2026 at 3:10 pm

    Try nlsn['Adj Close'][::-1].asfreq('M', method='ffill')

    And if you can get your function to return ascending order DatetimeIndex that would allow you to skip the extra sorting here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a python function that scrapes some data from a few different websites
I have the following python function that allows me to run shell commands from
I have a python function that makes a subprocess call to a shell script
I have a python function that randomize a dictionary representing a position specific scoring
I am working with datetime objects in python. I have a function that takes
I have a python function that contains an if-statement to check something. def my_func(a,
I have a python function that gets an array called row. Typically row contains
I have am writing a Python function that takes a timeout value as a
I have a python function defined as follows which i use to delete from
I have an expensive function that takes and returns a small amount of data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.