Skip to content

Instantly share code, notes, and snippets.

View franklinokech's full-sized avatar
🎯
Focusing

franklinokech franklinokech

🎯
Focusing
View GitHub Profile
@franklinokech
franklinokech / rproject_nitialization.R
Last active May 17, 2024 07:00
R data mananagament functions
# Load necessary package
library(here)
# Function to create a directory if it doesn't exist and include a README file
create_dir_if_not_exist <- function(dir_name) {
dir_path <- here(dir_name)
if (!dir.exists(dir_path)) {
dir.create(dir_path, recursive = TRUE)
message("Directory created: ", dir_path)
# Create README file
@franklinokech
franklinokech / MoveRows.js
Created September 15, 2020 13:42
a script to move google sheet records
function onOpen() {
var ui = SpreadsheetApp.getUi();
// Or DocumentApp or FormApp.
ui.createMenu('Main Menu')
.addItem('Create Tallying Sheet', 'copy2')
.addItem('Archive Data', 'archive_data')
.addToUi();
}
@franklinokech
franklinokech / setDateInGsheet.js
Last active September 14, 2020 08:16
Google App Script to set date when a column in a Gsheet is selected
//get date of entry
function onEdit(e) {
var ss = SpreadsheetApp.getActiveSheet();
var r = ss.getActiveCell();
//1.Change 'Sheet1' to be matching your sheet name
if (r.getColumn() < 9 && ss.getName()=='Data_entry') { // 2. If Edit is done in any column before Column (I) And sheet name is Sheet1 then:
var celladdress ='I'+ r.getRowIndex()
ss.getRange(celladdress).setValue(new Date()).setNumberFormat("MM/dd/yyyy");
}
@franklinokech
franklinokech / clearContent.js
Created September 14, 2020 07:47
A Google App Script to clear content of a Google spreadsheet
// funtion to clear the mpesa upload for new entries
function clearRange() {
// get spreasheet details
var sheet = SpreadsheetApp.getActive().getSheetByName('Mpesa upload summary');
// get the cell range and call clear method
sheet.getRange('B2:E').clearContent();
}
@franklinokech
franklinokech / python_to_gsheet.py
Created June 27, 2020 18:22
A Gist to authentifcate Google Sheet With Python Gspread Library
# Authenticate to Google drive and get the required dataset
from google.colab import auth
auth.authenticate_user()
import gspread
from gspread_dataframe import get_as_dataframe, set_with_dataframe
from oauth2client.client import GoogleCredentials
gc = gspread.authorize(GoogleCredentials.get_application_default())
@franklinokech
franklinokech / add_column.py
Last active June 4, 2020 09:06
This gist contains the key data wrangling of python pandas
idx = 0
new_col = [7, 8, 9] # can be a list, a Series, an array or a scalar
df.insert(loc=idx, column='A', value=new_col)
@franklinokech
franklinokech / convert_date.py
Created May 27, 2020 10:41
convert a pandas data column to the correctly
pd.to_datetime(df.date_col, format='%d-%m-%Y')
@franklinokech
franklinokech / remove_trailing_spaces.py
Last active May 27, 2020 10:40
remove trailing and leading spaces in column names
[x.strip() for x in df.columns]
function onOpen() {
var ui = SpreadsheetApp.getUi();
// Or DocumentApp or FormApp.
ui.createMenu('Main Menu')
.addItem('Create Tallying Sheet', 'copy2')
.addToUi();
}
@franklinokech
franklinokech / py
Last active September 21, 2019 08:11
sum_numbers
print ("Adding all numbers from 0 to 100")
num = 0
print("Enter Your Minumum Number")
range_min = input()
print("Enter Your Maxium Number")
range_max = input()
#Converting strings to numbers
formated_range_min = int(range_min)
formated_range_max=int(range_max)