Search code examples
pythonpython-3.xattributeerror

In what way can i debug this attribute error in python?


I'm trying to follow a Regression tutorial for python as the stats model package does not seem to be working for me. So I got this far until I received an attribute error.

input:

import pandas as pd

data = pd.read_csv("China_FDIGDP.csv")

data1 = data.dropna()
data1.to_csv("data1.csv", index = False)

Data  = pd.read_csv("data1.csv")

print(Data)

x = pd.Data["GDP"].values()
y = pd.Data["FDI_net_in"].values()

Here's the output:

Traceback (most recent call last):
  File "FDI.py", line 20, in <module>
    x = pd.Data["GDP"].values()

AttributeError: module 'pandas' has no attribute 'Data'

What am I doing wrong?

Date    FDI_net_in          GDP 
0  1982  4.300000e+08  2.050897e+11
1  1983  6.360000e+08  2.306867e+11
2  1984  1.258000e+09  2.599465e+11
3  1985  1.659000e+09  3.094880e+11
4  1986  1.875000e+09  3.007581e+11
Index(['Date', 'FDI_net_in', 'GDP '], dtype='object')

Solution

  • Try this

    Data.columns = Data.columns.str.strip(' ') # remove tab spaces in column names 
    x = Data["GDP"].values
    y = Data["FDI_net_in"].values