Skip to content

Instantly share code, notes, and snippets.

View jmquintana79's full-sized avatar
💭
I may be slow to respond.

Juan Quintana jmquintana79

💭
I may be slow to respond.
View GitHub Profile
@jmquintana79
jmquintana79 / csv_pandas.py
Last active October 31, 2023 09:03
I/O between csv and pandas dataframe
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
@jmquintana79
jmquintana79 / get_path.py
Last active August 18, 2016 05:43
Get full path of current folder
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
@jmquintana79
jmquintana79 / mysql_pandas.py
Created November 5, 2015 15:24
mysql table to pandas dataframe
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')
@jmquintana79
jmquintana79 / arguments_parser.py
Last active February 19, 2018 08:56
parse python script arguments
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',
@jmquintana79
jmquintana79 / run_bashCommand.py
Last active January 5, 2020 22:01
run bash command in python
## 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))
@jmquintana79
jmquintana79 / info_head .py
Last active August 18, 2016 05:42
head python for scripts and for modules
#!/usr/bin/env python
#! coding=utf-8
""" FOR SCRIPT """
"""
Copyright (C), <<year>>
FILE RUN: <<filename>>
<<description>>
AUTHOR: <juan.armaguedon@gmail.com>
@jmquintana79
jmquintana79 / combinatorics.py
Last active October 2, 2017 01:09
combinatorics with "itertools" library
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)) )
@jmquintana79
jmquintana79 / library_datetime.py
Last active February 14, 2018 01:22
datetime library use
"""
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
@jmquintana79
jmquintana79 / dictionary.py
Last active October 4, 2017 04:02
dictionary use
# 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}
@jmquintana79
jmquintana79 / bash_commands.sh
Last active August 31, 2021 06:02
bash command list
# 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