I have encountered a problem in python.
I would want to append a column(list) into an existing excel.
I changed my excel into a dataframe but i do not know how to append the list into it.
Original:
I want to append the list. However, my rows start from 8 instead of 1.
I have tried the code below but encountered error.
df1 = read_excel(file_name, sheet_name=my_sheet, engine='openpyxl')
h = [2,3,4,5]
df1['List'] = h
ValueError: Length of values (4) does not match length of index (14)
Expected result:
Appreciate any help. Thank you
Your excel includes empty rows and your python is reading them. To make sure - print out your df:
display(df1)
If this is the case try filtering them out:
df1 = read_excel(file_name, sheet_name=my_sheet, engine='openpyxl', na_filter=True)
Alternatively, you can drop the empty rows after you read the excel:
df1 = read_excel(file_name, sheet_name=my_sheet, engine='openpyxl')
df1 = df1.dropna()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.