I have the following dataframe, read into pandas from a csv.
Fruit Apple Pear
Date
2016-03-30 Pear 1
2016-04-14 Pear 1
2016-04-14 Pear 1
2016-05-09 Apple 1
2016-05-18 Apple 1
2016-06-24 Pear 1
2016-06-27 Apple 1
2016-06-27 Pear 1
2016-06-28 Apple 1
2016-06-28 Apple 1
2016-07-05 Pear 1
I'd like it to look like this. It sums the duplicate rows and then drops the duplicate row. The value in the Fruit column doesn't matter at this point. I'll drop that column later.
Fruit Apple Pear
Date
2016-03-30 Pear 1
2016-04-14 Pear 2
2016-05-09 Apple 1
2016-05-18 Apple 1
2016-06-24 Pear 1
2016-06-27 Apple 1 1
2016-06-28 Apple 2
2016-06-28 Apple 1
2016-07-05 Pear 1
I tried using groupby, but it filled the Apple/Pear columns with 1s. I tried a for loop that if the next date index was the same as the current date index, it would += 1 to the respective Apple/Pear column. That failed because the type of the column, and my attempts to change the column type failed as well. Banging my head against this one and I can't get it.
The one thing I can do right is drop the duplicates with df = df.reset_index().drop_duplicates('Date',keep='last').set_index('Date')