简体   繁体   中英

Add data in the next empty row in python pandas

I'm making a small and simple program that put one name under another in an excel file, and i dont know how i can get the next empty row

I have this excel table:

Name
Carl

And i'm making a program to add new names. Here is the function:

def modifyexcel ():
        book = openpyxl.load_workbook (r'C:\Users\usuario\Desktop\prueba.xlsx')
        sheet = book ["a"]       
        sheet ["a3"] = str(entrada1.get())
        book.save (r'C:\Users\usuario\Desktop\prueba.xlsx')

But i need, instead of modifying the "a3" cell, modify the next row that is empty, so every time i add a new name it gets placed on the next empty row

you can just use google colab to modify your excel ! you can mount your csv or excel to google drive or just load the csv to the side bar! and copy path and paste it to your pandas read_csv or (read_excel is the same thing)!

https://colab.research.google.com/

from google.colab import files
import pandas as pd
#So first you read from your original excel
df=pd.read_csv('path')
list1=df.name.tolist()
##then create a variable to store your new name
name= "new name" #@param {type:"string"}
##append the new name to the list and return to pandas dataframe
list1.append(name)
df.name=list1

##output to csv and download
df.to_csv('newsheet.csv',index=False)
files.download('newsheet.csv')

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM