pandas


pandas dataframe shift dates


I have a dataframe that is indexed by dates. I'd like to shift just the dates, one business day forward (Monday-Friday), without changing the size or anything else. Is there a simple way to do this?
You can shift with 'B' (I think this requires numpy >= 1.7):
In [11]: rng = pd.to_datetime(['21-11-2013', '22-11-2013'])
In [12]: rng.shift(1, freq='B') # 1 business day
Out[12]:
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-11-22 00:00:00, 2013-11-25 00:00:00]
Length: 2, Freq: None, Timezone: None
On the Series (same on a DataFrame):
In [21]: s = pd.Series([1, 2], index=rng)
In [22]: s
Out[22]:
2013-11-21 1
2013-11-22 2
dtype: int64
In [23]: s.shift(1, freq='B')
Out[23]:
2013-11-22 1
2013-11-25 2
dtype: int64

Related Links

Why I can't change the series format?
Copy numpy array into Panda multiindex (same size)
Average Previous and Current Row - Pandas
seaborn pointplot above swarmplot
Edit field and append value to a python dataframe column
column_stack returns non cotiguous array
pandas: conditionally select a row cell for each column based on a mask
pandas custom function apply on melted dataframe
How to check for boolean codition in pandas dataframe
Reading batches of data from BigQuery into Datalab
Jupyter/ipywidgets sorting dataframe on two levels
Groupby.sum() giving ValueError: overflow in timedelta operation
Why does DataFrameGroupBy.boxplot method throw error when given argument “subplots=True/False”?
Calculate age in months - optimize date transformations in pandas
pandas: list of dictionaries grouped by key from df
Pandas data frames and matplotlib.pyplot

Categories

HOME
client
zeromq
heroku
platform-builder
sd-card
framework7
sqlite-net-extensions
spring-cloud-stream
youtube-api-v3
electronics
sqlite3
django-imagekit
directx
add
elasticsearch-hadoop
vifm
fancybox-3
midi
numeral.js
circular-dependency
static-libraries
ibm-odm
graphlab
django-admin
http-status-code-504
connection-string
swingx
object-detection
intentfilter
sqlcipher
opennlp
subdomains
primitive
gsoap
nouislider
socialengine
.net-4.0
functor
cloud-code
mpmediaquery
catalog
file-format
space-complexity
libvpx
abstract-class
theano.scan
leading-zero
elasticsearch-plugin
azure-ml
squib
awt
optix
firebase-admin
midl
websphere-mq-fte
google-datalayer
dotcover
hibernate-tools
errordocument
hendrix
celery-task
sage-one
directory-structure
dynamics-sl
wdf
home-directory
transmitfile
sigabrt
fadeout
apachebench
photobucket
ora-00900
thredds
kcachegrind
iiviewdeckcontroller
census
project-planning
starcluster
jquery-layout
system.net.webexception
undefined-reference
bundles
c18
gridfs
cos
type-equivalence
spring-portlet-mvc
netdna-api
hirefire
heartbeat
cinema-4d
imac
gin
castle-monorail
database-management
kdbg
photoshop-cs4
eqatec
paul-graham

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App