AttributeError While Creating a Function

Viewed 43

I tried to create a function that reads my file and the column I want it to read:

def read_row(file, column):
   main_df = np.array([])
   for df in pd.read_csv(file, chunksize = 100000):
     column_name = df.column.unique()
     main_df = np.append(main_df,column_name)
return(main_df)

However it shows AttributeError: 'DataFrame' object has no attribute 'column'. What should I put instead of column in df.column.unique()?

1 Answers

Use brackets [] instead dot notation:

column_name = df[column].unique()
Related