Bruno Bruno - 1 year ago 106
Python Question

Python Append an excel sheet into Pandas-DataFrame

I am trying to create a database and fill it with values gotten from an excel sheet.

My code:

new_db = pd.DataFrame()
workbook = pd.ExcelFile(filename)
df = workbook.parse('Sheet1')
print(df)
new_db.append(df)
print(new_db.head())


But whenever I seem to do this, I get an empty dataframe back.

My excel sheet however is packed with values. When it is printed(print(df)) it prints it out with ID values and all the correct columns and rows.

My knowledge with Pandas-Dataframes is limited so excuse me if I do not know something I should. All help is appreciated.

Answer Source

You need to reassign the df after appending to it, as @ayhan pointed out in the comments:

new_db = new_db.append(df)

From the Panda's Documentation for append, it returns an appended dataframe, which means you need to assign it to a variable.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download