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

Trying to implement networkx into graphicsscene
Merge two data frames based on common column values in Pandas
Combine two columns of numbers in dataframe into single column using pandas/python
Python Pandas has low CPU usage and not using all cores
Pandas Set on copy warning when using .loc
Merge very large csv using pandas or awk
seasonal_decompose: operands could not be broadcast together with shapes on a series
How to properly sample from a numpy.random.multivariate_normal (positive-semidefinite covariance matrix issue)
how to do logical operation between dataframe columns?
Console hangs up at the time of plotting
Pandas apply a function at fixed interval
float type column in pandas to convert to tuple/list
Getting an error with Pandas Panel boolean indexing
pandas dataframe subtraction causing nan
Pandas dataframe: truncate string fields
how to add new categorical column in pandas

Categories

HOME
oracle11g
azure-data-factory
mockito
google-play
alfresco
paw-app
survey
ckeditor
azure-media-services
node-notifier
esper
facebook-messenger-bot
maude-system
vifm
windows-azure-storage
django-simple-history
uitypeeditor
google-pagespeed
swiftlint
java-7
shopware
tdd
pepper
pingfederate
phpfox
windows-server-2000
primitive
madlib
xquery-3.0
pdb
google-sites-2016
textmate
jmonkeyengine
main
adobe-premiere
automake
webix-treetable
hp-ux
slick-3.0
osx-mavericks
revapi
boost-multi-index
np-complete
sqldf
hittest
gnome-shell-extensions
topbeat
time-and-attendance
trash
pcf
mathematica-frontend
plottable.js
storekit
rhino-servicebus
separator
icu4j
microbenchmark
sniffer
jscript.net
angularjs-ng-click
google-reader
elliptic-curve
valuechangelistener
dotnetnuke-5
eclipse-memory-analyzer
buster.js
html4
hungarian-algorithm
clipper
specification-pattern
rdoc
cascalog
parametric-equations
online-compilation
cufon
php-parser
blackberry-playbook
genshi
coredump
oncheckedchanged
jmock
lpeg
html-input
w3wp.exe
preference
ext3
database-management
javap
anti-piracy
thread-local-storage

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