[PYTHON] Remove rows with duplicate indexes in pandas DataFrame

It should be very simple, but it got stuck for a long time, so make a note

For example

                           data
2016-02-04 01:00:00+00:00   1
2016-02-04 01:00:00+00:00   1                  
2016-02-04 01:30:00+00:00   2
2016-02-04 01:30:00+00:00   2     
2016-02-04 02:00:00+00:00   3

If there is a DataFrame df like

grouped = df.groupby(level=0)  
df2 = grouped.last() 

so

                           data
2016-02-04 01:00:00+00:00   1                 
2016-02-04 01:30:00+00:00   2   
2016-02-04 02:00:00+00:00   3

Is obtained.

Recommended Posts

Remove rows with duplicate indexes in pandas DataFrame
Delete rows with arbitrary values in pandas DataFrame
Load csv with duplicate columns in pandas
Bulk Insert Pandas DataFrame with psycopg2
How to reassign index in pandas dataframe
[Python] Add total rows to Pandas DataFrame
Replace column names / values with pandas dataframe
Working with 3D data structures in pandas
Is there NaN in the pandas DataFrame?
Convenient time series aggregation with TimeGrouper in pandas
Remove extra strings in URLs with regular expressions
Handle integer types with missing values in Pandas
Save Pandas DataFrame as .csv.gz in Amazon S3
Add totals to rows and columns in pandas
How to remove duplicate elements in Python3 list
Check if the expected column exists in Pandas DataFrame
Extract N samples for each group with Pandas DataFrame
How to access with cache when reading_json in pandas
Fill outliers with NaN based on quartiles in Pandas
Convert numeric variables to categorical with thresholds in pandas