1/19/2022

pandas moving average

 

Average by 2 steps moving window

.

import pandas as pd
data=[100, 200, 100, 100, 200, 100]
df = pd.DataFrame(data)
df.rolling(2).mean()

.

    0
0 NaN
1 150.0
2 150.0
3 100.0
4 150.0
5 150.0


www.marearts.com
🙇ðŸŧ‍♂️

pandas pct_change(), function to find the percentage change in the time-series data.

 The rate of change between the previous data and the current data

.

import pandas as pd
data=[100, 200, 100, 100, 200, 100]
df = pd.DataFrame(data)
df.pct_change()

.

     0
0 NaN
1 1.0
2 -0.5
3 0.0
4 1.0
5 -0.5


www.marearts.com
🙇ðŸŧ‍♂️

pandas replace zeros with previous non zero value

 

Here, our example data is stock csv file.


Load data and print 

.

import pandas as pd
IBM_path = 'IBM-practice.csv'
df = pd.read_csv(IBM_path, delimiter=',', usecols=['Date', 'Open', 'High', 'Low', 'Close', 'Volume'])
print(df)

.

         Date        Open        High         Low       Close    Volume

0  2021-01-19  123.594643  123.891014  122.456978  123.346077   5646308

1  2021-01-20  123.996178  125.296364  122.906311  124.359467        10

2  2021-01-21  124.397705  126.424477  124.330788  125.860420         0

3  2021-01-22  115.391968  115.391968  112.198853  113.393883  39814421

4  2021-01-25  113.537285  114.282982  112.284897  113.365204  14315974

5  2021-01-26  113.938812  117.198853  113.212234  117.103249  11186656



replace zeros with previous non zero value & check

.

# Replace 0 to avoid dividing by 0 later on
df['Volume'].replace(to_replace=0, method='ffill', inplace=True)
print(df)

.

         Date        Open        High         Low       Close    Volume

0  2021-01-19  123.594643  123.891014  122.456978  123.346077   5646308

1  2021-01-20  123.996178  125.296364  122.906311  124.359467        10

2  2021-01-21  124.397705  126.424477  124.330788  125.860420        10

3  2021-01-22  115.391968  115.391968  112.198853  113.393883  39814421

4  2021-01-25  113.537285  114.282982  112.284897  113.365204  14315974

5  2021-01-26  113.938812  117.198853  113.212234  117.103249  11186656


Thank you.

www.marearts.com

🙇ðŸŧ‍♂️


1/12/2022

run your script or executable file on ubuntu startup

 Following the below steps

.

#xx is your script or executable file
#copy xx to /etc/init.d/xx

#give permission
chmod 755 /etc/init.d/xx

#-- register autostart
update-rc.d /etc/init.d/xx defaults
#-- remove autostart
update-rc.d -f /etc/init.d/xx remove

.

reboot and test.


🙇ðŸŧ‍♂️ Thank you.

www.marearts.com

git : How to remove a big file wrongly committed



error message:

remote: Resolving deltas: 100% (23/23), completed with 8 local objects.
remote: error: Trace: 2ffe6017a58c483deb760c27365127df2f67946ddad23f7e84f265b42c275992
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File xxxx.ckpt is 206.67 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.


solution

git filter-branch --tree-filter 'rm -rf path/to/your/file' HEAD
git push

The command '/bin/sh -c apt-get install -y curl' returned a non-zero code: 100 while docker build

 

ADD this 2 cmd in docker file


RUN apt-get -y upgrade
RUN apt-get -y update

Thank you!