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
  Dictionary in a list bashage 2 493 Dec-27-2023, 04:04 PM
Last Post: deanhystad
  filtering a list of dictionary as per given criteria jss 5 597 Dec-23-2023, 08:47 AM
Last Post: Gribouillis
  need to compare 2 values in a nested dictionary jss 2 794 Nov-30-2023, 03:17 PM
Last Post: Pedroski55
  Copying the order of another list with identical values gohanhango 7 1,060 Nov-29-2023, 09:17 PM
Last Post: Pedroski55
  Search Excel File with a list of values huzzug 4 1,147 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Sort a list of dictionaries by the only dictionary key Calab 1 452 Oct-27-2023, 03:03 PM
Last Post: buran
  Comparing List values to get indexes Edward_ 7 1,081 Jun-09-2023, 04:57 PM
Last Post: deanhystad
  Printing specific values out from a dictionary mcoliver88 6 1,315 Apr-12-2023, 08:10 PM
Last Post: deanhystad
  How to add list to dictionary? Kull_Khan 3 951 Apr-04-2023, 08:35 AM
Last Post: ClaytonMorrison
  Adding values with reduce() function from the list of tuples kinimod 10 2,512 Jan-24-2023, 08:22 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

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