Search code examples
pythonpandasdataframejupyter-notebookattributeerror

Python Pandas Using functions of a DataFrame 'function' object has no attribute 'dtypes'


Context:

I am working with dataBases and dataFrames, so i need to get some version of the dataFrame that i am extracting and transforming, so i decided to use .copy function to get independents DataFrames. I am using Jupyter Notebook.

Show an reproducible example

I am doing something similar than this example.

import pandas as pd

# Create DataFrame from Dictionary
technologies = {
    'Courses':["Spark","PySpark","Hadoop"],
    'Fee' :[20000,25000,26000],
    'Duration':['30day','40days','35days'],
    'Discount':[1000,2300,1500]
              }

raw = pd.DataFrame(technologies)

#Copy the dataFrame to have a BackUP

df = raw.copy

print(df)

OUTPUT:

<bound method NDFrame.copy of    Courses    Fee Duration  Discount
0    Spark  20000    30day      1000
1  PySpark  25000   40days      2300
2   Hadoop  26000   35days      1500>

Until this point everything seems well. But when i execute some function for that dataFrame, like dtypes to get all types of the elements of the dataframe.

df.dtypes

OUPUT:

AttributeError: 'function' object has no attribute 'dtypes'


Solution

  • DataFrame.copy is a method that returns a deep copy of the dataFrame by default (you can set deep=False to get a reference to the same dataFrame).

    df = raw.copy()
    df.dtypes
    

    enter image description here