Python Forum
Python dictionary with values as list to CSV
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python dictionary with values as list to CSV
#1
Hello,
I have a dictionary in this way
tdm={
word1: [0,0,0,1.....] -> 253 values in the list
word2: [0,25,0,2.....]
.
.
.
word 12,000: [0,30,0,1.....]
}
I want it to be converted to this form in CSV

TERM | 0 | 1 | 2 | ....... 252 |
------------------------------------|
word1 | 0 | 0 | 0 | ..........
word2 | 0 | 25 | 0 | .........
..
..
word12,000
----------------------------------

Can anyone please help me with this...I'm unable to find a way for more than 5 hrs now
Reply
#2
I'm not sure what you need. CVS stands for "Comma-separated values". It's very general. Is it a particular printing format you need, or do you want to save as .CVS?
Reply
#3
(Mar-27-2021, 04:22 PM)michael1789 Wrote: I'm not sure what you need. CVS stands for "Comma-separated values". It's very general. Is it a particular printing format you need, or do you want to save as .CVS?
Reply
#4
Yes,
I want to save it as .csv output file
Reply
#5
I got the answer,
Since no one was able to help with the answer, I will myself post it for someone who might need help with this question.

we just need to convert dictionary to pandas dataframe then apply transpose to it followed by df.to_csv
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Class-Aggregation and creating a list/dictionary IoannisDem 1 175 Oct-03-2021, 05:16 PM
Last Post: Yoriz
  How to pass list of values to a API request URL chetansaip99 0 476 Sep-28-2021, 07:37 AM
Last Post: chetansaip99
  Getting values from a dictionary brunolelli 5 1,079 Mar-31-2021, 11:57 PM
Last Post: snippsat
  Conceptualizing modulus. How to compare & communicate with values in a Dictionary Kaanyrvhok 7 1,226 Mar-15-2021, 05:43 PM
Last Post: Kaanyrvhok
  convert List with dictionaries to a single dictionary iamaghost 3 946 Jan-22-2021, 03:56 PM
Last Post: iamaghost
  How to discard list repeat values akanowhere 7 1,140 Dec-28-2020, 09:14 PM
Last Post: akanowhere
Sad Convert python list to dictionary akanowhere 6 1,190 Dec-27-2020, 09:26 PM
Last Post: Pedroski55
  Adding keys and values to a dictionary giladal 3 813 Nov-19-2020, 04:58 PM
Last Post: deanhystad
  Creating a dictionary from a list Inkanus 5 1,261 Nov-06-2020, 06:11 PM
Last Post: DeaD_EyE
  In this dictionary all the values end up the same. How? Pedroski55 2 672 Oct-29-2020, 12:32 AM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020