Skip to content

Instantly share code, notes, and snippets.

@javieroot
javieroot / guardar-csv.py
Created August 13, 2019 20:42 — forked from Fhernd/guardar-csv.py
Guarda datos de un DataFrame en formato CSV en Python.
import pandas as pd
# Definición diccionario:
diccionario = {'pares': [0, 2, 4, 6], 'impares': [1, 3, 5, 7]}
# Creación DataFrame:
df_numeros = pd.DataFrame(diccionario)
# Guarda datos en CSV:
df_numeros.to_csv('numeros.csv', header=False, index=False)
@javieroot
javieroot / mysql-pandas-import.py
Created August 8, 2019 22:30 — forked from stefanthoss/mysql-pandas-import.py
Import data from a MySQL database table into a Pandas DataFrame using the pymysql package.
import pandas as pd
import pymysql
from sqlalchemy import create_engine
engine = create_engine('mysql+pymysql://<user>:<password>@<host>[:<port>]/<dbname>')
df = pd.read_sql_query('SELECT * FROM table', engine)
df.head()
@javieroot
javieroot / ordenar-datos.py
Created August 8, 2019 16:38 — forked from Fhernd/ordenar-datos.py
Ordenar datos de un DataFrame en Python.
import pandas as pd
df = pd.DataFrame({'uno': [1, 2, 3], 'dos': [4, 5, 6], 'tres': [7, 8, 9]}, index=['x', 'y', 'z'])
print(df)
print()
# Orden por índice (fila):
print(df.sort_index())
@javieroot
javieroot / SqlAlchemyGet.py
Created May 25, 2019 21:21 — forked from Razzo78/SqlAlchemyGet.py
Python, SQL Server - Connect and get data with SqlAlchemy
from sqlalchemy import create_engine, MetaData, Table
from sqlalchemy.orm import mapper
from sqlalchemy.sql import select
class MyTable(object):
pass
# Trusted Connection
import pymssql
import pandas as pd
## instance a python db connection object- same form as psycopg2/python-mysql drivers also
conn = pymssql.connect(server="172.0.0.1", user="howens",password="some_fake_password", port=63642) # You can lookup the port number inside SQL server.
## Hey Look, college data
stmt = "SELECT * FROM AlumniMirror..someTable"
# Excute Query here
df = pd.read_sql(stmt,conn)
@javieroot
javieroot / pandas-dummy-variables.txt
Created May 24, 2019 23:15 — forked from sethbunke/pandas-dummy-variables.txt
Simple example of creating dummy variables using Python Pandas
#import pandas and numpy
import pandas as pd
import numpy as np
#create dataframe with some random data
df = pd.DataFrame(np.random.rand(10, 2) * 10, columns=['Price', 'Qty'])
#add a column with random string values that would need to have dummy variables created for them
df['City'] = [np.random.choice(('Chicago', 'Boston', 'New York')) for i in range(df.shape[0])]
@javieroot
javieroot / agregarComandosCmder.txt
Last active March 21, 2019 01:11
Se agregan rsync, curl y wget a Cmder en bash::mintty
# Para abrir cmder desde la carpeta del usuario (el equivalente al home del usuario), editar poniendo cd en el archivo:
# $CMDER_ROOT/config/user_profile.sh
# rsync (esta forma podría funcionar para algún comando más, es cosa de probar que no den error por las dll que pueden
# necesitar)
# Fuente:
# https://discourse.gohugo.io/t/rsync-deploy-and-windows-10/10137/4
1) Descargar como .pkg.tar.xz la última versión del comando que se quiere agregar de http://repo.msys2.org/msys/x86_64/
Por ejemplo, rsync
@javieroot
javieroot / certs.sh
Created March 6, 2019 00:07 — forked from joakinen/certs.sh
Converting certificates
#!/bin/sh
# ____ _____ ____ _____ ___ _____ ___ ____ _ _____ _____ ____
# / ___| ____| _ \_ _|_ _| ___|_ _/ ___| / \|_ _| ____/ ___|
# | | | _| | |_) || | | || |_ | | | / _ \ | | | _| \___ \
# | |___| |___| _ < | | | || _| | | |___ / ___ \| | | |___ ___) |
# \____|_____|_| \_\|_| |___|_| |___\____/_/ \_\_| |_____|____/
# ____ _______ __
# | _ \| ___\ \/ /
@javieroot
javieroot / comandosGit.sh
Last active August 29, 2020 00:00
Comandos para la administración de repositorios git
# Iniciar un repositorio vacío en el directorio actual aunque existan archivos, estos se deben agregar enseguida con git add
git init
# Hacer una copia local de un repositorio
git clone nombre_url_repositorio
# Agregar configuración del usuario actual
git config --global user.email "usuario@dominio"
git config --global user.name "usuario"
# Cómo ver los valores de la configuración, por ejemplo los anteriores y los alias definidos en git
@javieroot
javieroot / excel_read.py
Created August 22, 2018 17:14 — forked from dlouapre/excel_read.py
Read excel file in Python
# -*- coding: utf-8 -*-
import xlrd
# Open the file
wb = xlrd.open_workbook('test.xlsx')
# Get the list of the sheets name
sheet_list = wb.sheet_names()
print sheet_list