2

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
  • It's a bit unclear what your variables are trying to achieve. Is column a string or an integer? If column was an integer and you're actually tring to get the column name it would be column_name = df.columns[column]. If that's not the case, you should consider adjusting your variable names. Commented Jan 25, 2022 at 8:48

1 Answer 1

1

Use brackets [] instead dot notation:

column_name = df[column].unique()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.