groupby first and last modify datatype · Issue #2763 · pandas-dev/pandas (original) (raw)
Navigation Menu
- GitHub Copilot Write better code with AI
- GitHub Models New Manage and compare prompts
- GitHub Advanced Security Find and fix vulnerabilities
- Actions Automate any workflow
- Codespaces Instant dev environments
- Issues Plan and track work
- Code Review Manage code changes
- Discussions Collaborate outside of code
- Code Search Find more, search less
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Description
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