How to transpose and flatten csv with missing values to be transposed?

I have a csv with roughly the following format.

|Website | Value | Date | 2010-01 | 2010-02 | 2010-03 | ... |
|-------|--------|------|---------|---------|---------|-----|
|abc.com| .3789  |2010-01|        |         |         |     |
|abc.com| .4786  |2010-03|        |         |         |     |
|bbc.com| .76    |2010-02|        |         |         |     |

I would like to flatten rows with the same website value, effectively transposing the value field into columns 4 and beyond that have dates as titles. Like so:

|Website | 2010-01 | 2010-02 | 2010-03 | additional dates |
|-------|----------|---------|---------|------------------|
|abc.com|  .3789   |         | .4786   |                  |
|bbc.com|          |.76      |         |                  |

It’s easy enough to match up the value field with the date titled column based on the date field. But this leaves a “stepping down” shape to the data, instead of value field flattened within one row per unique website value. Any tips on where to look?

Answer

Use pivot_table:

>>> df[["Website", "Value", "Date"]].pivot_table(index="Website", values="Value", columns="Date")
Date     2010-01  2010-02  2010-03
Website                           
abc.com   0.3789      NaN   0.4786
bbc.com      NaN     0.76      NaN