This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def updateData(df): | |
| data = df.loc[:,['profesi_master','updated_at','userid']].values.tolist() | |
| sql_update =""" | |
| UPDATE tblcustomfieldsvalues | |
| SET value = %s, updated_at = %s | |
| WHERE relid = %s | |
| """ | |
| mycursor1 = connWarehouse.cursor() | |
| mycursor1.executemany(sql_update,data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .replace(/"/g,'\\"').replace(/'/g,"\\'") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pymongo | |
| import json | |
| from datetime import datetime, timedelta, date, timezone | |
| from pymongo import MongoClient | |
| import datetime as dd | |
| # 1. Create Connection | |
| client = MongoClient( | |
| host = '123.456.789', | |
| port = int(27017), # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Concat WS | |
| df.groupby(['name','month'])['text'].apply(','.join).reset_index() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # cara 1 | |
| import os | |
| ip = '127.0.0.1' | |
| ls = os.system('ping -c 4 {}'.format(ip)) | |
| # cara 2 | |
| from subprocess import check_output | |
| out = check_output(["ping", "-c 5", "127.0.0.1"]) | |
| splt = out.decode().split('ping statistics') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def generateBatch(df,isi_batch): | |
| df.reset_index(drop=True,inplace=True) # agar index dimulai berurut dari 0,1,2,...dst | |
| total = len(df) # total baris | |
| batas_kelas = list(range(0,total,int(isi_batch))) # batas atas dan bawah tiap batch | |
| ls1 = [] | |
| for k in range(len(batas_kelas)): | |
| try: | |
| df1 = df.iloc[batas_kelas[k]:batas_kelas[k+1],] | |
| ls1.append(df1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| word = ['sdn 2 pamulung','smp 2 makassar','sman3 boyolaly'] | |
| # Exact match | |
| for k in word: | |
| try: | |
| print(re.search('^sdn 2 pamulung$|^smpn$|^sman$',k).group()) | |
| except: | |
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| sys.path.insert(1, '/home/bisdev/work/jupyter-notebooks/Connections') | |
| from AppleConnection import DBConnection |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| text = 'Hubungi saya di email bisnis201@gmail.com atau bisnis101@gmail.com @#$%' | |
| # \ : memberitahu bahwa huruf yang dipakai adalah pola regex bukan normal charaters | |
| # \w : mendapatkan word | |
| # \w+@ : mendapatkan word yang mengandung @ dan juga direturn | |
| # \w+@+\w+ : mencari karakter yang didalamnya terdapat @ diantara keduanya | |
| re.findall('\w+@+\w+',text) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # import data | |
| url = 'https://raw.githubusercontent.com/arofiqimaulana/Datacamp-Course/master/Writing%20Efficient%20Code%20in%20Python/baseball_stats.csv' | |
| baseball_df = pd.read_csv(url) | |
| # Fungsi Menghitung Persentase Menang | |
| def calc_percentWin(df): | |
| wins = df['W'] # total menang | |
| games_played = df['G'] # total bermain | |
| win_perc = np.round(wins/games_played,2) |
NewerOlder