Timestamp is undefined - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Timestamp is undefined (/thread-16049.html) |
Timestamp is undefined - ErnestTBass - Feb-12-2019 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 RE: Timestamp is undefined - buran - Feb-12-2019 show your code in python tags as well as full traceback in error tags RE: Timestamp is undefined - ErnestTBass - Feb-12-2019 Sorry, I thought that I had pt it in the first post. O have zipped it and attached it to the post. Respectfully, ErnestTBasss RE: Timestamp is undefined - buran - Feb-12-2019 please, copy paste the python code, don't upload a zipped Jupyter Notebook ipynb file Not every one uses Jupyter RE: Timestamp is undefined - ErnestTBass - Feb-14-2019 #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 syntaxNow 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 definedPlease explain what is wrong and how to correct the error. Any help appreciated. Thanks in advance. Respectfully, ErnestTBass RE: Timestamp is undefined - snippsat - Feb-14-2019 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. RE: Timestamp is undefined - ErnestTBass - Feb-16-2019 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 RE: Timestamp is undefined - snippsat - Feb-16-2019 (Feb-16-2019, 08:06 PM)ErnestTBass Wrote: what can I do to modify that line so that it runs as an Python script?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) |