Python Dictionary to CSV

后端 未结 6 774
情深已故
情深已故 2020-11-27 16:09

I have written code to read a CSV into a python dictionary, which works fine. I\'m trying to get the dictionary back to a CSV. I have written the following:

         


        
6条回答
  •  难免孤独
    2020-11-27 16:40

    Easiest Way

    You can convert the dictionary into Dataframe and write it to csv Eg

    import pandas as pd
    my_dict = {"tester": 1, "testers": 2}
    df=pd.DataFrame(my_dict,index=[0])
    df.to_csv("path and name of your csv.csv")
    

    output

       tester  testers
    0       1        2
    

提交回复
热议问题