I did not find enough benefit to use pandas here, as the problem is simple.
Also pay attention to the OP, if you want to save the values ββin a read-only file, just use the JSON or Python shelf module. Export to CSV should be minimized only when we need to interact with potential Excel users.
The code below converts words to CSV
value1 = 'one' value2 = 'two' d = { 'key1': (value1, value2), 'key2': (value1, value2), 'key3': (value1, value2) } CSV ="\n".join([k+','+','.join(v) for k,v in d.items()]) #You can store this CSV string variable to file as below # with open("filename.csv", "w") as file: # file.write(CSV)
This code explains what happens inside the list comprehension.
CSV = "" for k,v in d.items(): line = "{},{}\n".format(k, ",".join(v)) CSV+=line print CSV
source share