import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import style

 

style.use(‘fivethirtyeight’)
bridge_readings={‘Distance_mm’:[50012,50015,50009,5024012,50007,50016,50014]}
df=pd.DataFrame(bridge_readings)
##df.plot()
##plt.show()
stats=df.describe()
print stats
print “standard deviation is “,stats.Distance_mm[‘std’]

#to convert the data from enotation to float

pd.options.display.float_format = ‘{:20,.2f}’.format
#to find the rolling standard deviation
df[‘std’]=pd.rolling_std(df[‘Distance_mm’],2)
print df.head()

#using this method we can see where the deviation skyrockets

#so if we want to print the data where the std is lower than the entire std
#using this method we can remove the extremely high valued variance part
df=df[(df[‘std’]<stats.Distance_mm[‘std’])]

print df.head()

#we could also make the standard deviation less than a constant for example 50

df=df[(df[‘std’]<50)]
print df.head()

df[‘Distance_mm’].plot()
plt.show()

Advertisements

import datetime

import pandas_datareader.data as web
import matplotlib.pyplot as plt
from matplotlib import style
from statistics import mean

style.use(‘fivethirtyeight’)

import rlcompleter, readline
try:
import readline
except ImportError:
import pyreadline as readline
import pandas as pd

def moving_average(data):

return mean(data)

def fancy_this(data):
return mean(data)+mean(data)+5
start=datetime.datetime(2005,1,1)
end=datetime.datetime(2015,1,1)
att=web.DataReader(‘T’,’yahoo’,start,end)
describe=att.describe()
att[’50MA’]=pd.rolling_mean(att[‘Close’],50)

att[’10MA’]=pd.rolling_mean(att[‘Close’],4)

att[’50STD’]=pd.rolling_std(att[‘Close’],50)

att[‘MA_with_apply’]=pd.rolling_apply(att[‘Close’],50,moving_average)

att[‘Something_fancy’]=pd.rolling_apply(att[‘Close’],50,fancy_this)

 

 

print att.head()
print ‘************************************************************’

 

att.dropna(how=’all’,inplace=True)
print att.head()
print ‘************************************************************’
#there are two kind of filling one is forward fill and another is backward fill
#in case of forward fill suppose row1 has the value of 5 and row2 and row3 is none
#in forward fill row3 will take the value five
#in backward fill the exact opposite will happen

att.fillna(method=’ffill’,inplace=True)
print att.head()
print ‘************************************************************’

att.fillna(method=’bfill’,inplace=True)
print att.head()

#to replace NaN with predetermined values
#to see the results we have to comment out previous filtered data

 

print ‘************************************************************’

att.fillna(value=-99999, inplace=True)
print att.head()

##to fill a percentage of dataframe with predetermined values
##say for example one percent

 

print ‘************************************************************’
percent=0.01
one_pct=int(len(att)*percent)
att.fillna(value=-99999, inplace=True, limit=one_pct)
print att

 

#if we want to find out after replacing a percentage of NaN if there are still NaN in the dataframe

if att.isnull().values.sum() > 1:
print ‘there are more NaN in the dataframe,to be precise more than ‘, int(percent*100) ,’%’

import datetime

import pandas_datareader.data as web
import matplotlib.pyplot as plt
from matplotlib import style
from statistics import mean

style.use(‘fivethirtyeight’)

import rlcompleter, readline
try:
import readline
except ImportError:
import pyreadline as readline
import pandas as pd

def moving_average(data):

return mean(data)

def fancy_this(data):
return mean(data)+mean(data)+5
start=datetime.datetime(2005,1,1)
end=datetime.datetime(2015,1,1)
att=web.DataReader(‘T’,’yahoo’,start,end)
describe=att.describe()
att[’50MA’]=pd.rolling_mean(att[‘Close’],50)

att[’10MA’]=pd.rolling_mean(att[‘Close’],4)

att[’50STD’]=pd.rolling_std(att[‘Close’],50)

att[‘MA_with_apply’]=pd.rolling_apply(att[‘Close’],50,moving_average)

att[‘Something_fancy’]=pd.rolling_apply(att[‘Close’],50,fancy_this)

#this is for dropping the entire column which has NaN

#att.dropna(inplace=True)

 

print att.head()

att2=att.dropna()
print att2.head()

#the output will show side by side in att frame many rows has NaN but in att2 those rows were omitted

 

#however if we want to see the columns which have some Nan but also many important data below,so in summary we want to see
#the all the rows

att3=att.dropna(how=’all’)
print att3.head()

 

import datetime

import pandas_datareader.data as web
import matplotlib.pyplot as plt
from matplotlib import style
from statistics import mean

style.use(‘fivethirtyeight’)

import rlcompleter, readline
try:
import readline
except ImportError:
import pyreadline as readline
import pandas as pd

def moving_average(data):

return mean(data)

def fancy_this(data):
return mean(data)+mean(data)+5
start=datetime.datetime(2005,1,1)
end=datetime.datetime(2015,1,1)
att=web.DataReader(‘T’,’yahoo’,start,end)
describe=att.describe()
att[’50MA’]=pd.rolling_mean(att[‘Close’],50)

att[’10MA’]=pd.rolling_mean(att[‘Close’],10)

att[’50STD’]=pd.rolling_std(att[‘Close’],50)

att[‘MA_with_apply’]=pd.rolling_apply(att[‘Close’],50,moving_average)

att[‘Something_fancy’]=pd.rolling_apply(att[‘Close’],50,fancy_this)

 

print att.tail()

 

 

I just love python 2.7,it has small footprints,fast,elegant,many resources can be found on python 2.7 online.so many libraries are available for python 2.7 that a lot of serious development can be done without inventing the wheel again and again.

However there are some issues like the statistics module is not available,so if you try

pip install statistics,you will be faced with an error

To overcome this

you need to download the file get-pip.py from this location

https://bootstrap.pypa.io/get-pip.py

Then go to your python 2.7 directory ,for my pc it is in the C folder,I have both python 3.6 and 2.7,however i prefer python 2.7,but when I type python in command prompt the python always shows as python 3.6,that’s why to excuisitely run python 2.7  I need to go to python2.7 folder in C drive

python get-pip.py

The statistics module should be installed this way

you can taste it by import statistics command

Source

https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=94333

https://pip.pypa.io/en/stable/installing/

 

 

 

 

import datetime
import pandas_datareader.data as web
import matplotlib.pyplot as plt
from matplotlib import style
style.use(‘fivethirtyeight’)

import rlcompleter, readline
try:
import readline
except ImportError:
import pyreadline as readline
import pandas as pd
start=datetime.datetime(2005,1,1)
end=datetime.datetime(2015,1,1)
att=web.DataReader(‘T’,’yahoo’,start,end)
describe=att.describe()
att[’50MA’]=pd.rolling_mean(att[‘Close’],50)

att[’10MA’]=pd.rolling_mean(att[‘Close’],10)

#if we use att.head() the moving averages will be shown as Nan
#because moving averages depends on previous values,so it’s
#better to use tail()

 

#print att.tail()

fig, axes=plt.subplots(nrows=2, ncols=1)
att[’50STD’]=pd.rolling_std(att[‘Close’],50)
att[’50STD’].plot(ax=axes[1],label=’50STD’ )
att[‘Close’].plot(ax=axes[0],label=’Price’)
att[’10MA’].plot(ax=axes[0],label=’10MA’)
att[’50MA’].plot(ax=axes[0],label=’50MA’)
plt.legend(loc=4)

plt.show()

import datetime
import pandas_datareader.data as web
import matplotlib.pyplot as plt
from matplotlib import style
style.use(‘fivethirtyeight’)

import rlcompleter, readline
try:
import readline
except ImportError:
import pyreadline as readline
import pandas as pd
start=datetime.datetime(2005,1,1)
end=datetime.datetime(2015,1,1)
att=web.DataReader(‘T’,’yahoo’,start,end)

print att.head()
print 80*’#’
#to see the statistical measurements such as
#count mean std min 25% 50% 75% max

print att.describe()

#to see the statistical measurements for a particular column such as for example OPEN

describe=att.describe()
print 80*’#’
print describe[‘Open’]

#to see one single statistical measurement such as for example
#standard deviation for a given column
print 80*’#’
print ‘The standdard Deviation of Open Column is {:0.2f}.\n’.format(describe[‘Open’][‘std’])

 

###now if you type something like att[‘Open’] and the column does not exist it
###it will create the column,butif it exists the comn will be modified
###create a column named Open_Original to retain the values of the Open column
##
##att[‘Open_Original’]=att[‘Open’]
##att[‘Open_Modified’]=att[‘Open’]/10
##
##att[‘high-low’]=att[‘High’]-att[‘Low’]
##att[‘Daily_Rise’]=att[‘Close’]>att[‘Open’]
##del att[‘Open’]
##print att.head()
##
###say for example we only wants to print the rows in this dataframe where
###a condition satisfies for example we like to print the rows where
###the day close is greater than day open
##print 80*’#’
##attfilter=att[(att[‘Close’]>att[‘Open_Original’])]
##print attfilter.head()
##
###say for example we only wants to print the rows in this dataframe where
###a condition satisfies for example we like to print the rows where
###the day high is greater than day close and the difference is equal to or greater than 1 dollar
##
##print 80*’#’
##attfilter2=att[((att[‘High’]-att[‘Low’])>1)]
##print attfilter2.head()
##

import datetime
import pandas_datareader.data as web
import matplotlib.pyplot as plt
from matplotlib import style
style.use(‘fivethirtyeight’)

import rlcompleter, readline
try:
import readline
except ImportError:
import pyreadline as readline
import pandas as pd
start=datetime.datetime(2005,1,1)
end=datetime.datetime(2015,1,1)
att=web.DataReader(‘T’,’yahoo’,start,end)

print att.head()
print 80*’#’
#now if you type something like att[‘Open’] and the column does not exist it
#it will create the column,butif it exists the comn will be modified
#create a column named Open_Original to retain the values of the Open column

att[‘Open_Original’]=att[‘Open’]
att[‘Open_Modified’]=att[‘Open’]/10

att[‘high-low’]=att[‘High’]-att[‘Low’]
att[‘Daily_Rise’]=att[‘Close’]>att[‘Open’]
del att[‘Open’]
print att.head()

#say for example we only wants to print the rows in this dataframe where
#a condition satisfies for example we like to print the rows where
#the day close is greater than day open
print 80*’#’
attfilter=att[(att[‘Close’]>att[‘Open_Original’])]
print attfilter.head()

#say for example we only wants to print the rows in this dataframe where
#a condition satisfies for example we like to print the rows where
#the day high is greater than day close and the difference is equal to or greater than 1 dollar

print 80*’#’
attfilter2=att[((att[‘High’]-att[‘Low’])>1)]
print attfilter2.head()

import datetime
import pandas_datareader.data as web
import matplotlib.pyplot as plt
from matplotlib import style
style.use(‘fivethirtyeight’)

import rlcompleter, readline
try:
import readline
except ImportError:
import pyreadline as readline
import pandas as pd
start=datetime.datetime(2005,1,1)
end=datetime.datetime(2015,1,1)
att=web.DataReader(‘T’,’yahoo’,start,end)

print att.head()
print 80*’#’
#now if you type something like att[‘Open’] and the column does not exist it
#it will create the column,butif it exists the comn will be modified
#create a column named Open_Original to retain the values of the Open column

att[‘Open_Original’]=att[‘Open’]
att[‘Open_Modified’]=att[‘Open’]/10
del att[‘Open’]
att[‘high-low’]=att[‘High’]-att[‘Low’]
print att.head()

import time
import os
import ctypes

arr2=[]
arr= os.listdir(“C:\Users\sourav\Desktop\python scripts”)
for arrs in arr:
if arrs.endswith(‘.jpg’):
arr2.append(arrs)

#print arr2
print “C:\Users\sourav\Desktop\python scripts\\”+arr2[0]
for i in range(0,len(arr2)):

SPI_SETDESKWALLPAPER = 20

ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, “C:\Users\sourav\Desktop\python scripts\\”+arr2[i] , 0)
time.sleep(10)

Older Posts »

Categories

%d bloggers like this: