Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Timestamp is undefined
I am receiving the following error. The timestamis undefined. I am not sure
how to correct it.

I know that must import something. I am just not sure what.

Any help appreciated.

Thanks in advance.


show your code in python tags as well as full traceback in error tags
Sorry, I thought that I had pt it in the first post.

O have zipped it and attached it to the post.



Attached Files
.zip (Size: 39.34 KB / Downloads: 6)
please, copy paste the python code, don't upload a zipped Jupyter Notebook ipynb file
Not every one uses Jupyter
#creating dataframe with date and target variable
data = df.sort_index(ascending=True, axis=0)
new_data = pd.DataFrame(index=range(0,len(df)),columns=['Date', 'Close'])

#import packages
import pandas as pd
import numpy as np

#to plot notebook
import matplotlib.pyplot as plt
%matplotlib inline

#setting figure size
from matplotlib.pylab import rcParams
rcParams["figure.figsize"] = 20,10

#for normalizing data
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler(feature_range=(0,1))

#read the file 
df = pd.read_csv('NSE-BSE.csv')

#print the head

#setting index as date
df['Date'] = pd.to_datetime(df.Date,format ='%Y-%m-%d')
df.index = df['Date']

plt.plot(df['Close'], label='Close Price History')
Above is the code is the code as I got it from my *.ipynb file.

Now if you run it you will get a matlibplot error as shown below. I am ut how to get rid of it. It works fine on
jupyter notebook.

File "", line 11
    %matplotlib inline
SyntaxError: invalid syntax
Now with that error corrected (please explain what to do to correct the error)
when we run the code this is the response that I get.

NameError                                 Traceback (most recent call last)
<ipython-input-4-0549f4648bc4> in <module>
---> 20 (Timestamp('2013-10-08 00:00:00'),
     21 Timestamp('2017-10-06 00:00:00'),
     22 Timestamp('2017-10-09 00:00:00'),

NameError: name 'Timestamp' is not defined
Please explain what is wrong and how to correct the error.

Any help appreciated. Thanks in advance.


File "", line 11 %matplotlib inline ^ SyntaxError: invalid syntax
This is made to be executed in Jupyter NoteBook,you can not run with %matplotlib inline as ordinary Python script.
Also missing NSE-BSE.csv that this code load.

Do you know how to run Jupyter Notebook?
Take a look at this post for basic setup.
You can install with pip or eg use Anacona3.

There also online clould version like Microsoft Azure Notebooks and Google Colaboratory.
buran likes this post
I understand that I cannot run %matplotlib inline as an ordinary python script, so
what can I do to modify that line so that it runs as an Python script?

There must be someway to modify it.

Any help appreciated. Thanks in advance.


(Feb-16-2019, 08:06 PM)ErnestTBass Wrote: what can I do to modify that line so that it runs as an Python script?

There must be someway to modify it.
Look at this post again.
There i use to show it as image(png) when run as a script outside of NoteBook.
plt.plot(x,y, label='Loaded from file!')
plt.title('Graph x y')
plt.legend(loc='upper left', shadow=True, fontsize='large')
Inside NoteBook it's one line,if not doing any modification to Graph.
df.plot(x='x_data', y='y_data' figsize=(7 ,3)

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  dealing with big data of timestamp LMQ 0 225 Jul-27-2018, 01:23 PM
Last Post: LMQ
  python charmap codec can't decode byte X in position Y character maps to < undefined> owais 9 14,683 Apr-28-2018, 10:52 PM
Last Post: abadawi
  write data each second into file with timestamp br0ken 8 1,765 Dec-06-2017, 09:33 AM
Last Post: br0ken
  Timestamp doesn't change with each loop lwhistler 2 1,262 Aug-23-2017, 06:58 PM
Last Post: bowen73
  timestamp not updating bowen73 3 1,687 Aug-20-2017, 11:13 PM
Last Post: bowen73
  Python code with serial port and global undefined marciokoko 13 4,727 Jan-17-2017, 06:14 PM
Last Post: micseydel
  matplotlib timestamp zero_shubh0 2 2,213 Dec-02-2016, 02:12 PM
Last Post: zero_shubh0
  How to timestamp a Python program, your thoughts? Orthoducks 2 1,467 Dec-02-2016, 12:06 AM
Last Post: Orthoducks

Forum Jump:

Users browsing this thread: 1 Guest(s)