Python Forum

Full Version: Running Python 2.7 program
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to run the following snippet of code. It is python 2.7 and it is in Windows 10 Professional'




import pandas as pd # data manipulation library
import numpy as np # numerical computation library
import datetime as dt

import matplotlib.pyplot as plt # plotting library
from matplotlib import cm # color maps for plotting
plt.style.use('ggplot') # use the ggplot plotting style

%matplotlib inline #show plots in line in a jupyter notebook

from __future__ import division # division without truncating decimals

nfl = pd.read_csv('https://raw.githubusercontent.com/ryurko/nflscrapR-data/master/data/season_play_by_play/pbp_


But it is not interpreting.

I get the following error. It is in the comments and it makes no sense.

Error:
UsageError: unrecognized arguments: #show plots in line in a jupyter notebook
In this code at first it did not like the line that imports matplotlib.pyplot as plt.

I fixed it by uninstalling matplotlib and then reinstalling it.

Now it had the same issue with Pandas and Numpy. I uninstalled and reinstalled each module then
they worked.


Then this error occurred as shown above. I am confused. Each time I uninstalled and reinstalled the module
it worked,but a new issue popped up.

I know that should not be using python 2.7, but the code was originally Python 2.7.

I believe there is a program, actually a *.bat file that can take python 2 code and make it python 3.

It is not perfect, but anything is better than chasing your tail which is what I am doing now.

Can this piece of python 2.7 code be fixed? Should I use said program to upgrade the code to Python 3?

Any help appreciated.

Respectfully,

ErnestTBass
%matplotlib inline #show plots in line in a jupyter notebook
Comments are not allowed on the line with one of these "magic" commands. That's why the error you're getting only shows the comment. Remove the comment or place it on a separate line.
(Oct-21-2020, 03:56 AM)ErnestTBass Wrote: [ -> ]I know that should not be using python 2.7, but the code was originally Python 2.7.
Python 2 is dead Angel
NumPy and Matplotlib do in newer version not support Python 2,only Python 3.
So pip install numpy will not work in Python 2.

Here demo in a Notebook,and code works fine.