I'm sure I have a small error here that I'm overlooking, but am having a tough time figuring out what I need to change.

Here is my code up until the error I'm getting.

# Load libraries
import pandas as pd
import numpy as np
from pandas.tools.plotting import scatter_matrix
import matplotlib.pyplot as plt
from sklearn import model_selection
from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix
from sklearn.metrics import accuracy_score
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.discriminant_analyisis import LinearDiscriminantAnalysis
from sklearn.naive_bayes import GaussianNB
from sklearn.svm import SVC

# Load dataset
names = ['action','reject','approve','occ','loanamt', 'suffolk', 'appinc','typur','unit','married','dep','emp',yjob','self','atotinc','cototinc','hexp']

# from azureml import Workspace
# ws = Workspace(
#      workspace_id='',
#      authorization_token='==',
#      endpoint='https://studioapi.azureml.net'
# )
# ds = ws.datasets['loanapp_c.csv']

ds = pd.read_csv('desktop/python ML/loanapp_c.csv')
dataset = ds.to_dataframe()

I was running this on Azure and am now trying to do it locally. Here is the error I'm getting:

AttributeError                Traceback (most recent call last)
<ipython-input-3-b49a23658806> in <module>()
     33 ds = pd.read_csv('desktop/python ML/loanapp_c.csv')
---> 34 dataset = ds.to_dataframe()
     36 # shape

~/anaconda3/lib/python3.7/site-packages/pandas/core/generic.py in_getattr_(self, name)
     4374 if self._info_axis.can_hold_identifiers_and_holds_name(name):
            return self[name]
  -> 4376 return object._getattribute_(self,name)
     4378 def _setattr_(self, name, value):

AttributeError: 'DataFrame' object has no attribute 'to_dataframe'

Not sure what I have wrong.


2 Answers 2


The function pd.read_csv() is already a DataFrame and thus that kind of object does not support calling .to_dataframe().

You can check the type of your variable ds using print(type(ds)), you will see that it is a pandas DataFrame type.


According to what I understand. You are loading loanapp_c.csv in ds using this code:

ds = pd.read_csv('desktop/python ML/loanapp_c.csv')

ds over here is a DataFrame object. What you are doing is calling to_dataframe on an object which a DataFrame already.

Removing this dataset = ds.to_dataframe() from your code should solve the error

  • $\begingroup$ I just set dataset = ds and that fixed it. Thanks for your help! $\endgroup$
    – user68346
    Commented Feb 24, 2019 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.