concat() drops index when used on series with a PeriodIndex · Issue #1815 · 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
New to this, sorry if I'm just missing something...
import numpy as np import pandas as pd
d1 = pd.date_range('12/31/1990', '12/31/1999', freq='A-DEC') d2 = pd.date_range('12/31/2000', '12/31/2009', freq='A-DEC')
s1 = pd.Series(np.random.randn(10), d1) s2 = pd.Series(np.random.randn(10), d2)
works
pd.concat([s1,s2])
s1 = s1.to_period() s2 = s2.to_period()
drops index
pd.concat([s1,s2])
workaround
pd.concat([s1.to_timestamp(), s2.to_timestamp()]).to_period('A-DEC')