groupby first and last modify datatype · Issue #2763 · pandas-dev/pandas (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

@courosh

Description

@courosh

Using groupby(level=0).first() or groupby(level=0).last() to eliminate duplicate index entries modifies integer data types to float.

import pandas as pd
idx = range(10)
idx.append(9)
df = pd.Series(data=range(11), index=idx, name='IntCol')
print df
print df.dtype

0     0
1     1
2     2
3     3
4     4
5     5
6     6
7     7
8     8
9     9
9    10
Name: IntCol
int64

df2 = df.groupby(level=0).first()
print df2
print df2.dtype

0    0
1    1
2    2
3    3
4    4
5    5
6    6
7    7
8    8
9    9
float64