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

  • SEARCH
  • Home
  • 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 8653085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:27:31+00:00 2026-06-12T14:27:31+00:00

I am using Pandas 0.8.1 to fetch Yahoo stock price from datetime import datetime

  • 0

I am using Pandas 0.8.1 to fetch Yahoo stock price

from datetime import datetime
from pandas.io.data import DataReader

stk_price = DataReader('600809.ss', 'yahoo', datetime(2006,1,1), datetime(2012,12,31)).reset_index()

>>> stk_price.Date
0    2010-01-04 00:00:00
1    2010-01-05 00:00:00
2    2010-01-06 00:00:00
3    2010-01-07 00:00:00
4    2010-01-08 00:00:00

And I want to convert the Date to string by:

>>>stk_price.Date.astype('|S10')
0     1970-01-15
1     1970-01-15
2     1970-01-15
3     1970-01-15
4     1970-01-15
5     1970-01-15

Why it shows “1970-01-15” instead of “2010-01-04” etc ? How to fix it?

And if I have a

DATE_LIST = [
 u'20090331', u'20090630', u'20090930', u'20091231', \
 u'20100331', u'20100630', u'20100930', u'20101231', \
 u'20110331', u'20110630', u'20110930', u'20111231', \
 u'20120331', u'20120630', u'20120930', u'20121231'
 ]

I just try to filter the rows of stk_price whose Date column is in DATE_LIST by below:

from datetime import datetime
from pandas.io.data import DataReader
import numpy as np

DATE_LIST = [
 u'20090331', u'20090630', u'20090930', u'20091231', \
 u'20100331', u'20100630', u'20100930', u'20101231', \
 u'20110331', u'20110630', u'20110930', u'20111231', \
 u'20120331', u'20120630', u'20120930', u'20121231'
 ]

DATE_ARRAY = np.array(DATE_LIST,dtype='datetime64[us]')
stk_price = DataReader('600809.ss', 'yahoo', datetime(2006,1,1), datetime(2012,12,31)).reset_index()
rst = stk_price[stk_price.Date.isin(DATE_ARRAY)].Close

but the rst is empty .

How to fix it or any Pandas function can filter the result ?

  • 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-12T14:27:32+00:00Added an answer on June 12, 2026 at 2:27 pm

    Instead of converting stk_price dates to strings (which shows the wrong dates due to a numpy bug, see also github issue #1802) you can also convert the DATE_LIST to timestamps and use these directly to index stk_price. Below an example on frame containing random data.

    In [16]: DATE_LIST = [
     u'20090331', u'20090630', u'20090930', u'20091231', \
     u'20100331', u'20100630', u'20100930', u'20101231', \
     u'20110331', u'20110630', u'20110930', u'20111231', \
     u'20120331', u'20120630', u'20120930', u'20121231'
     ]
    
    In [17]: timestamps = [pd.Timestamp(date) for date in DATE_LIST]
    
    In [18]: df = pd.DataFrame(np.random.randn(100,3), index=pd.date_range('20090331', periods=100))
    
    In [19]: df.ix[timestamps].dropna()
    Out[19]:
                       0         1         2
    2009-03-31  0.520235  1.158889 -0.310227
    2009-06-30  1.036449  0.528931 -0.083166
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using import datetime in python, is it possible to take a formatted time/date string
I have the following pandas Dataframe: from pandas import DataFrame, MultiIndex index = MultiIndex.from_tuples(zip([21,22,23],[45,45,46]),
Using Core Data, I have a fetch request to fetch the minimum of a
I'm using python pandas for data analysis and I want to change the name
I am using the pandas.ols function from version 0.7.3. I seem to be getting
I try to read .txt with missing values using pandas.read_csv. My data is of
I am trying to add seconds to python datetime excluding weekends using pandas. The
I'm using read_csv to read CSV files into Pandas data frames. My CSV files
I have aggregated data using pandas data frame. Below is some actual data shown
I'm using the pandas library to read in some CSV data. In my 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.