Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Timestamp is undefined
#1
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.

Respectfully,,

ErnestTBass
Reply
#2
show your code in python tags as well as full traceback in error tags
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Sorry, I thought that I had pt it in the first post.

O have zipped it and attached it to the post.


Respectfully,

ErnestTBasss

Attached Files

.zip   test1.zip (Size: 39.34 KB / Downloads: 182)
Reply
#4
please, copy paste the python code, don't upload a zipped Jupyter Notebook ipynb file
Not every one uses Jupyter
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
#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
df.head()






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

#plot
plt.figure(figsize=(16,8))
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 "testx.py", 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>
     18 
     19 
---> 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.

Respectfully,

ErnestTBass
Reply
#6
Error:
File "testx.py", 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.
Reply
#7
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.

Respectfully,

ErnestTBass
Reply
#8
(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 plt.show() to show it as image(png) when run as a script outside of NoteBook.
plt.plot(x,y, label='Loaded from file!')
plt.xlabel('x')
plt.ylabel('y')
plt.title('Graph x y')
plt.legend(loc='upper left', shadow=True, fontsize='large')
plt.show()
Inside NoteBook it's one line,if not doing any modification to Graph.
df.plot(x='x_data', y='y_data' figsize=(7 ,3)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  undefined function error JonWayn 5 1,402 Sep-11-2022, 03:38 AM
Last Post: JonWayn
  Undefined Led_Zeppelin 4 1,368 Aug-02-2022, 11:57 AM
Last Post: buran
  error in timestamp Led_Zeppelin 3 3,106 Jun-15-2022, 08:28 PM
Last Post: deanhystad
  error in timestamp Led_Zeppelin 0 980 Jun-10-2022, 07:59 PM
Last Post: Led_Zeppelin
  ImportError: /home/pybind11_example.cpython-37m-x86_64-linux-gnu.so: undefined symbol chaitra 2 5,029 Feb-03-2021, 05:14 AM
Last Post: chaitra
  name "MyVariable" can be undefined Advisability 1 2,391 Aug-20-2020, 02:05 PM
Last Post: Gribouillis
  function error: undefined variable Atlantic_3000 3 6,866 Apr-12-2020, 02:53 AM
Last Post: bowlofred
  name undefined Coding Error Ewilliam51 2 2,100 Feb-06-2020, 12:19 AM
Last Post: Ewilliam51
  python charmap codec can't decode byte X in position Y character maps to < undefined> owais 9 38,913 Apr-28-2018, 10:52 PM
Last Post: abadawi
  timestamp not updating bowen73 3 7,124 Aug-20-2017, 11:13 PM
Last Post: bowen73

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020