I am attacking a problem at work that requires me to convert a list of columns into a unique CSV format. I say unique because I have not seen an explanation on SO for my particular issue. My research steered me toward a couple of similar questions, such as the ones by Sameer Patel and user1403483, which I tried, but the output was incorrect; let me explain.
Here is an example of my data:
animals = [['dog',
['a','b','c','d'],
['aa','aa'],
['bb','bb','bb','bb','bb']],
['cat',
['a','b','c'],
[''],
['bb','bb']],
['bear',
['a'],
['aa','aa','aa'],
['bb']]]
The problem requires that the format of the CSV (when opened in Excel) appear as follows:
+------+------+------+------+
| dog | a | aa | bb |
+------+------+------+------+
| | b | aa | bb |
+------+------+------+------+
| | c | | bb |
+------+------+------+------+
| | d | | bb |
+------+------+------+------+
| | | | bb |
+------+------+------+------+
| cat | a | | bb |
+------+------+------+------+
| | b | | bb |
+------+------+------+------+
| | c | | |
+------+------+------+------+
| bear | a | aa | bb |
+------+------+------+------+
| | | aa | |
+------+------+------+------+
| | | aa | |
+------+------+------+------+
Is there a Python function in pprint,
csv,
or pandas
to do this, or do I need to create one, to produce the CSV output to create the table?