Skip to content

Instantly share code, notes, and snippets.

@ljwolf
Last active June 14, 2018 19:15
Show Gist options
  • Save ljwolf/ba3f41df984d7064440e8a24e25ae9f1 to your computer and use it in GitHub Desktop.
Save ljwolf/ba3f41df984d7064440e8a24e25ae9f1 to your computer and use it in GitHub Desktop.
Pandas Rolling String example
import pandas as pd
import string
df = pd.DataFrame([[*string.ascii_letters[0:26:2]],
*string.ascii_letters[1:26:2]])
rolled = df.rolling(window=2, center=False, axis=1).apply(lambda x: ''.join(x))
#expected: [['ac', 'ce', 'eg', 'gi', 'ik', 'km', 'mo', 'oq', 'qs', 'su', 'uw', 'wy'],
# 'bd', 'df', 'fh', 'hj', 'jl', 'ln', 'np', 'pr', 'rt', 'tv', 'vx', 'xz']]
print(rolled.values)
#is the original dataframe
@y9c
Copy link

y9c commented Jun 14, 2018

not work...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment