Bottom Page

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
Quote
#2
show your code in python tags as well as full traceback in error tags
Quote
#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: 20)
Quote
#4
please, copy paste the python code, don't upload a zipped Jupyter Notebook ipynb file
Not every one uses Jupyter
Quote
#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
Quote
#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.
buran likes this post
Quote
#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
Quote
#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)
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Replace last 4 bytes of a timestamp mPlummers 18 542 Sep-17-2019, 12:47 AM
Last Post: Larz60+
  How to convert different timestamp formats? python_newbie09 12 391 Aug-05-2019, 06:37 PM
Last Post: python_newbie09
  dealing with big data of timestamp LMQ 0 427 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 21,080 Apr-28-2018, 10:52 PM
Last Post: abadawi
  write data each second into file with timestamp br0ken 8 3,153 Dec-06-2017, 09:33 AM
Last Post: br0ken
  Timestamp doesn't change with each loop lwhistler 2 2,099 Aug-23-2017, 06:58 PM
Last Post: bowen73
  timestamp not updating bowen73 3 2,448 Aug-20-2017, 11:13 PM
Last Post: bowen73
  Python code with serial port and global undefined marciokoko 13 6,158 Jan-17-2017, 06:14 PM
Last Post: micseydel
  matplotlib timestamp zero_shubh0 2 2,872 Dec-02-2016, 02:12 PM
Last Post: zero_shubh0
  How to timestamp a Python program, your thoughts? Orthoducks 2 1,825 Dec-02-2016, 12:06 AM
Last Post: Orthoducks

Forum Jump:


Users browsing this thread: 1 Guest(s)