Skip to content

Instantly share code, notes, and snippets.

Vinicius Roggério da Rocha viniroger

Block or report user

Report or block viniroger

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@viniroger
viniroger / print_control.py
Created Oct 31, 2019
Print message to follow process evaluation
View print_control.py
@staticmethod
def print_control(place, day):
"""
Print dates/place control
"""
#print('%s - %s' %(place, day))
import sys
sys.stdout.write('%s - %s\r' %(place, day))
sys.stdout.flush()
@viniroger
viniroger / replace_value.py
Created Oct 23, 2019
Replace value at dataframe without "A value is trying to be set on a copy of a slice from a DataFrame" warning
View replace_value.py
import pandas as pd
# Loop for all rows
for i in range(0,df.shape[0]):
# Repace value
df.loc[i, 'column_name'] = 5.2
@viniroger
viniroger / fixed_columns.py
Created Oct 18, 2019
Save dataframe at file with same width columns
View fixed_columns.py
import pandas as pd
df1 = pd.read_csv('input.csv', delimiter=';', header=None)
# Save into fixed columns file
import numpy as np
with open('output.dat', 'w') as ofile:
fmt = '%5d %4d %4d %4d %11.4f %11.4f %11.4f %11.4f %11.4f %11.4f %11.4f %11.4f %11.4f %11.4f %11.4f %11.4f'
np.savetxt(ofile, df1.values, fmt=fmt)
@viniroger
viniroger / get_sonda_data.sh
Last active Oct 18, 2019
Create URLs and download data from multiples links automatically
View get_sonda_data.sh
#!/bin/bash
# Download files from network
places=('BRB' 'PTR' 'SMS')
years=($(seq 2012 2018))
months=({01..12})
mkdir -p data_amb
for place in "${places[@]}"; do
echo $place
@viniroger
viniroger / calc_mean.py
Created Oct 15, 2019
Read CSV with timestamp and calculate 5-min average
View calc_mean.py
def str_to_datetime(s, format_in):
"""
Convert all elements of a pandas series into datetime format
"""
import time
from datetime import datetime
from time import mktime
# Convert from day of year from strptime structure
strptime_object = s.apply(lambda x: time.strptime(x, format_in))
# Create datetime object
@viniroger
viniroger / print_all.py
Last active Oct 7, 2019
Print all elements from array
View print_all.py
# Print all numpy array, without truncation
import sys
import numpy
numpy.set_printoptions(threshold=sys.maxsize)
# Print all pandas dataframe, without truncation
with pd.option_context('display.max_rows', None, 'display.max_columns', None): # more options can be specified also
print(df)
@viniroger
viniroger / filtro.py
Created Aug 8, 2019
Ideas for extreme value filter
View filtro.py
def filtro(self, df, uid):
"""Filter forecasted values
Check acceptable values, replacing when it isn't
"""
import statistics
if uid == 215:
lower_limit = 10
upper_limit = 3000
elif uid == 216:
lower_limit = 10
@viniroger
viniroger / convert.py
Created Jul 22, 2019
Convert object to datetime64 ns and print columns types
View convert.py
y_true['ds'] = pd.to_datetime(y_true['ds'])
print(y_true.dtypes)
@viniroger
viniroger / zip_files.sh
Created Jul 10, 2019
Select files by pattern and zip into new file
View zip_files.sh
ls *VS00* *VSS.* | zip -@ saida/arquivo.zip
@viniroger
viniroger / send_mail.sh
Last active Jul 10, 2019
Shell script to send e-mail with attachments and body to mails list
View send_mail.sh
envio_email(){
# Escrever corpo do e-mail
echo "Seguem anexos" >> $arq_email
printf "\n" >> $arq_email
# Arquivo de texto no corpo de e-mail
cat $arq_descr >> $arq_email
# Criar lista de e-mails a partir de arquivo
readarray -t lista_emails < <(cat $DIR/helpers/destinatarios_teste.txt | grep $grupo | awk -F',' '{print $1}')
You can’t perform that action at this time.