I am new to Machine learning. I am trying to plot the input data. but it gives me syntax error:
"C:\Users\shafi\AppData\Local\Temp/ipykernel_14876/3654013207.py", line 1 plt.scatter(year,per capita income (US$),color='blue',marker=' ') ^ SyntaxError: invalid syntax
import pandas as pd
import numpy as np
from sklearn import linear_model
import matplotlib.pyplot as plt
df=pd.read_csv('E:/CV (ALL FOR JOB)/ALL PROJECTS/5. IMAGE DETECTION/canada.csv')
df
df.head(3)
%matplotlib inline
plt.xlabel('year',fontsize=20)
plt.ylabel('per capita income (US$)',fontsize=20)
plt.scatter(df.year,df.per capita income (US$),color='blue',marker=' ')
CodePudding user response:
per capita income (US$)
is not a valid python identifier:
plt.scatter(df.year, df['per capita income (US$)'], color='blue', marker=' ')
You should avoid dot-notation if your column names are not valid python identifiers and use []
to avoid SyntaxError
exception.