Skip to content

Instantly share code, notes, and snippets.

@sam-thecoder
Created August 7, 2018 07:00
Show Gist options
  • Save sam-thecoder/8e30148565491b190cf5e3ba9c4f28f4 to your computer and use it in GitHub Desktop.
Save sam-thecoder/8e30148565491b190cf5e3ba9c4f28f4 to your computer and use it in GitHub Desktop.
def count_drop(numbers):
return len([x for x in numbers if x < 0])
def count_up(numbers):
return len([x for x in numbers if x > 0])
df['Change'] = df['Value USD'] - df['Value 2']
df.drop('Value 2', axis=1, inplace=True)
#Change for the past 7 days
df['Mean Change 7'] = df['Change'].rolling(7).mean()
#number of times the price dropped the last 7 days
df['Drop 7'] = df['Change'].rolling(7).apply(count_drop, raw=True)
#number of times the price increased the last 7 days
df['Up 7'] = df['Change'].rolling(7).apply(count_up, raw=True)
#drop rows with NA's created at the first days missing history to compare
df.dropna(inplace=True)
#reset the index
df.reset_index(drop=True, inplace=True)
df.head(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment