python list to csv file with each item in new line

后端 未结 5 649
无人及你
无人及你 2021-01-19 02:10

I am trying to write a function that takes in a list of strings and writes each String in the list as a separate row in a csv file, but I am not getting any output. Could yo

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-19 02:46

    Why don't you try doing it with pandas instead. It's super easy. :)

    lst = ['name@domain.com', 'name@domain.com', 'name@domain.com', 'name@domain.com', 'name@domain.com', 'name@domain.com']
    

    First, import package

    import pandas
    

    Then, create dataframe

    df = pandas.DataFrame(data={"email": lst})
    

    Then, export to csv :)

    df.to_csv("./mycsv.csv", sep=',',index=False)
    

    Done :) let me know if this one works for you!

提交回复
热议问题