0

I am trying to assign new_df the dataframe but it says that new_df is not defined. is there a way that I can assign dataframe to the new_df variable using a function.

`def concat(file_xlsx, "sheet1", new_df): for f in file_xlsx: data=pd.read_excel(file_xlsx,"sheet1") new_df=pandas.Dataframe.append(data) return new_df` 
3
  • How are you creating the Dataframe that will be passed into the function? Commented Feb 12, 2021 at 12:07
  • What is x in your function? You have a for loop over that (presumably iterable) object. Commented Feb 12, 2021 at 12:12
  • I edited x out with file_xlsx. So, file_xlsx is a list excel workbooks. I am trying to join them to create a complete dataframe. Commented Feb 12, 2021 at 13:28

1 Answer 1

1
# create an Empty DataFrame object new_df = pd.DataFrame() def concat(file_xlsx, "sheet1", new_df): for f in file_xlsx: data=pd.read_excel(file_xlsx,"sheet1") # and then append data into it new_df=pandas.Dataframe.append(data) return new_df 

You are appending data into a data frame without creating a data frame. First, you need to create a data frame(can be an empty data frame) and then append data on it. Please take a look into the above code snippet by me.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.