How to append new row to dataframe in pandas?

前端 未结 4 833
臣服心动
臣服心动 2021-02-13 19:29

This is the code i have used

    iname = \"name1\"    
    ipassword = \"password1\"
    iemail = \"email@domain.com\"
    res1 = []
            


        
4条回答
  •  遥遥无期
    2021-02-13 20:13

    You can use pd.DataFrame.loc to add a row to your dataframe:

    iname = "name1"    
    ipassword = "password1"
    iemail = "email@domain.com"
    
    df = pd.read_csv("login.csv", sep=',', encoding="utf-8")
    
    df.loc[df.index.max()+1] = [iname, ipassword, iemail]
    
    df.to_csv("login.csv", index=False)
    

提交回复
热议问题