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

TypeError when changing an integer data series in pandas
Pandas file IO Read Error
Pandas — asof() by last on DataFrame
Pandas Column Construction with np.where()
MultiIndex-based indexing in pandas
How to get the number of the most frequent value in a column?
Using pandas.ols on multiple dependent variables at once
Insert 0-values for missing dates within MultiIndex
Reindexing dataframes
pandas access axis by user-defined name
Trouble with groupss and aggregation
Replace MultiIndex's contents with DataFrame columns
What's the `DataFrameGroupBy`-equivalent of `dict.keys`?
How to split a dataframe according to a boolean criterion?
Pandas Rolling Computations on Sliding Windows (Unevenly spaced)
Resampling Minute data

Categories

HOME
pandas
variables
heroku
json.net
ip
facebook-messenger-bot
iggrid
here-api
fancybox-3
spring-kafka
windows-server-2012
caml
transformation
facebook-page
normalizr
beyondcompare
samoa
opencover
jquery-ajaxq
mps
format-specifiers
dxf
rundeck
sqlcipher
apache-commons-io
windows-error-reporting
strncpy
xacml
buck
large-file-upload
libuv
kendo-datasource
bpel
azure-sql-database
gammu
mmenu
force-layout
bower-install
file-format
devextreme
c11
particles.js
flashair
sas-jmp
cubic-spline
rainbowtable
pnotify
sage-one
epson
spring-mongodb
time-and-attendance
medium.com
adxstudio-portals
pcf
plottable.js
fuzzy-search
gridview-sorting
contact-list
testng-dataprovider
master-slave
make-install
apachebench
dataview
suffix-tree
sdhc
wireshark-dissector
libressl
kcachegrind
twirl
key-management
sonarqube5.1.2
proj4js
skos
jsapi
dd
bitcoinj
contenttype
funcunit
braille
cloud-connect
aqtime
plasma
interface-orientation
ember-app-kit
android-hardware
referrer
automount
errai
buildr
window-management
xtype
yetanotherforum
html-input
visitor-statistic
sudzc
subviews
meego
sustainable-pace
signal-handling

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