I am trying to find linear regression plot for the data provided
JavaScript
x
10
10
1
import pandas
2
from pandas import DataFrame
3
import matplotlib.pyplot
4
5
data = pandas.read_csv('cost_revenue_clean.csv')
6
data.describe()
7
8
X = DataFrame(data,columns=['production_budget_usd'])
9
y = DataFrame(data,columns=['worldwide_gross_usd'])
10
when I try to plot it
JavaScript
1
3
1
matplotlib.pyplot.scatter(X,y)
2
matplotlib.pyplot.show()
3
the plot was completely empty and when I printed the type of X
JavaScript
1
3
1
for element in X:
2
print(type(element))
3
it shows the type is string.. Where am I standing wrong???
Advertisement
Answer
No need to make new DataFrames for X
and y
. Try astype(float)
if you want them as numeric:
JavaScript
1
3
1
X = data['production_budget_usd'].astype(float)
2
y = data['worldwide_gross_usd'].astype(float)
3