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 9179765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:52:57+00:00 2026-06-17T17:52:57+00:00

first, if I use DataReader to read in the data, and then plot, everything

  • 0

first, if I use DataReader to read in the data, and then plot, everything is good

In [55]: t = DataReader('SPY','yahoo', start=datetime.datetime(1990,1,1))

In [56]: t
Out[56]: 
<class 'pandas.core.frame.DataFrame'>
Index: 5033 entries, 1993-01-29 00:00:00 to 2013-01-23 00:00:00
Data columns:
Open         5033  non-null values
High         5033  non-null values
Low          5033  non-null values
Close        5033  non-null values
Volume       5033  non-null values
Adj Close    5033  non-null values
dtypes: float64(5), int64(1)

In [58]: t.plot()
Out[58]: <matplotlib.axes.AxesSubplot at 0x8cca790>

However, if I save it as a csv file and reload it again, I got error message and the plot is not quite right either,

In [62]: t.to_csv('spy.csv')

In [63]: s = pd.read_csv('spy.csv', na_values=[" "])

In [64]: s.set_index('Date')
Out[64]: 
<class 'pandas.core.frame.DataFrame'>
Index: 5033 entries, 1993-01-29 00:00:00 to 2013-01-23 00:00:00
Data columns:
Open         5033  non-null values
High         5033  non-null values
Low          5033  non-null values
Close        5033  non-null values
Volume       5033  non-null values
Adj Close    5033  non-null values
dtypes: float64(5), int64(1)

In [66]: s.plot()                                                            
--------------------------------------------------------------------------- 
AttributeError                            Traceback (most recent call last) 
/home/dli/pythonTest/pandas/<ipython-input-66-d3eb09d34df4> in <module>()   
----> 1 s.plot()                                                            

/usr/lib/pymodules/python2.7/pandas/core/frame.pyc in plot(self, subplots, sharex, sharey, use_index, figsize, grid, legend, rot, ax, kind, **kwds)
3748                     ax.legend(loc='best')                              
3749                 else:                                                  
-> 3750                     ax.plot(x, y, label=str(col), **kwds)           
3751                                                                        
3752                 ax.grid(grid)                                          

/usr/lib/pymodules/python2.7/matplotlib/axes.pyc in plot(self, *args, **kwargs)
3891         lines = []                                                     
3892                                                                        
-> 3893         for line in self._get_lines(*args, **kwargs):               
3894             self.add_line(line)                                        
3895             lines.append(line)                                         

/usr/lib/pymodules/python2.7/matplotlib/axes.pyc in _grab_next_args(self, *args, **kwargs)
    320                 return                                              
    321             if len(remaining) <= 3:                                 
--> 322                 for seg in self._plot_args(remaining, kwargs):      
    323                     yield seg                                       
    324                 return                                              

/usr/lib/pymodules/python2.7/matplotlib/axes.pyc in _plot_args(self, tup, kwargs)
    279         ret = []                                                    
    280         if len(tup) > 1 and is_string_like(tup[-1]):                
--> 281             linestyle, marker, color = _process_plot_format(tup[-1])
    282             tup = tup[:-1]                                          
    283         elif len(tup) == 3:                                         

/usr/lib/pymodules/python2.7/matplotlib/axes.pyc in _process_plot_format(fmt)
    93     # handle the multi char special cases and strip them from the    

    94     # string                                                         

---> 95     if fmt.find('--')>=0:                                           
    96         linestyle = '--'                                             
    97         fmt = fmt.replace('--', '')                                  

AttributeError: 'numpy.ndarray' object has no attribute 'find'            

Any idea how to fix it?

Thanks.
Dan

  • 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-17T17:52:58+00:00Added an answer on June 17, 2026 at 5:52 pm

    The set_index method returns a new DataFrame by default, rather than applying this inplace (in fact, most pandas functions are similar). It has an inplace argument:

    s.set_index('Date', inplace=True)
    s.plot()
    

    which works as you intended!

    Note: to convert the Index to a DatetimeIndex you can use to_datetime:

    s.index = s.index.to_datetime()
    

    .

    Which is to say, s remained unchanged by you .set_index('Date'):

    In [63]: s = pd.read_csv('spy.csv', na_values=[" "])
    
    In [64]: s.set_index('Date')
    Out[64]: 
    <class 'pandas.core.frame.DataFrame'>
    Index: 5033 entries, 1993-01-29 00:00:00 to 2013-01-23 00:00:00
    Data columns:
    Open         5033  non-null values
    High         5033  non-null values
    Low          5033  non-null values
    Close        5033  non-null values
    Volume       5033  non-null values
    Adj Close    5033  non-null values
    dtypes: float64(5), int64(1)
    
    In [65]: s
    Out[65]: 
    <class 'pandas.core.frame.DataFrame'>
    Int64Index: 5033 entries, 0 to 5032
    Data columns:
    Date         5033  non-null values
    Open         5033  non-null values
    High         5033  non-null values
    Low          5033  non-null values
    Close        5033  non-null values
    Volume       5033  non-null values
    Adj Close    5033  non-null values
    dtypes: float64(5), int64(1), object(1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

R newbie here. If I first use map('state') , how can I then use
I know one awkward solution for this taks will be : first use ct
we want to have the second biggest element. We first use ANY to exclude
first time use JTree. Just wondering is it possible to have more than one
I divide dynamic websites into two types: The first one use e.g PHP ,
I want to lazy load of @Lob properties. First ,i use javassist to instrument
First off I use this code to make the navigation bar always stay fixed;
First attempt to use this cool site - after searching for 2 hours: So
I use my first query to get the id and name of the user
I just use foursquare first time, looks it find my location and shows on

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.