This file contains 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 pandas | |
from datetime import datetime | |
## CSV to PANDAS | |
# basic | |
path = 'path_file_input.csv' | |
data_df = pandas.read_csv(path,sep=";",index_col=0,usecols=['col1','col2']) | |
# reading japanese characters |
This file contains 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 os | |
# For getting the current directory of your script: | |
os.path.dirname(os.path.abspath(__file__)) | |
#For getting the current working directory: | |
os.getcwd() | |
# Build a path |
This file contains 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 MySQLdb | |
import pandas as pd | |
#### EXECUTE MYSQL QUERY function | |
def dfquery( query , value_index_col ): | |
# get mysql connection | |
con = MySQLdb.connect(host='127.0.0.1',user='xxx',passwd='xxx') | |
This file contains 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 argparse | |
# Functions here | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser(description='Create Marketing Report') | |
parser.add_argument('--accounts', | |
action='store_true', | |
help='Process Account Data') | |
parser.add_argument('--sales', |
This file contains 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
## RUN BASH COMMAND IN PYTHON | |
import subprocess | |
scommand = './script.sh' | |
_ = subprocess.call(scommand, shell=True) | |
## RUN BASH COMMAND IN PYTHON with error control | |
from subprocess import run, PIPE | |
result = run("./script.sh", stdout=PIPE, stderr=PIPE, universal_newlines=True) # universal_newline: stdout/stderr strings with or without newline (str or byte) | |
print('returncode: %s\nstdout: %s\nstderr: %s'%(result.returncode, result.stdout, result.stderr)) |
This file contains 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
#!/usr/bin/env python | |
#! coding=utf-8 | |
""" FOR SCRIPT """ | |
""" | |
Copyright (C), <<year>> | |
FILE RUN: <<filename>> | |
<<description>> | |
AUTHOR: <[email protected]> |
This file contains 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 itertools | |
lx = ["1","2","3","4"] | |
# combinations | |
print( "Combiantions: %s"%list(itertools.combinations(lx,r=2)) ) | |
# permutations | |
print( "Permutations: %s"%list(itertools.permutations(lx,r=2)) ) | |
# product | |
print( "Permutations with replacement (product): %s"%list(itertools.product(lx,repeat=2)) ) | |
# combinations with replacement | |
print( "Combinations with replacement: %s"%list(itertools.combinations_with_replacement(lx,r=2)) ) |
This file contains 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
""" | |
class datetime.date | |
An idealized naive date, assuming the current Gregorian calendar always was, and always will be, in effect. | |
Attributes: year, month, and day. | |
class datetime.time | |
An idealized time, independent of any particular day, assuming that every day has exactly 24*60*60 seconds (there is no notion of “leap seconds” here). | |
Attributes: hour, minute, second, microsecond, and tzinfo. | |
class datetime.datetime |
This file contains 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
# example | |
d={'var1':1, 'var2':2} | |
# GET INDEX AND VALUES | |
print d.keys() # ['var1', 'var2'] | |
print d.values() # [1, 2] | |
# FIND INDEX BY VALUE | |
mydict = {'george':16,'amber':19} |
This file contains 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
# COPY recursive | |
cp -r folder folder_cp | |
# EXPORT PATH | |
export PATH=$PATH:/"folder of application"/ | |
# COUNT number lines into a file | |
wc -l path_file | |
# SEARCH text in files |
OlderNewer