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
# create a virtual env called myvirtualenv | |
virtualenv myvirtualenv | |
# activate the virtual environment and install everything from requirements | |
source myvirtualenv/bin/activate | |
pip install -r requirements.txt | |
# check which venv you are in | |
which python |
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
# When working with R files created using locales that are not installed, this is how you generate new ones. | |
# Works on Ubuntu 20.04.4 LTS | |
# prints out locales that are already created and accessible. | |
locale -a | |
# generate a new one, for example French | |
locale-gen fr | |
# Update the locales so that R can access them |
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
name: data-visualization | |
dependencies: | |
- python=3.9.7 | |
- pandas | |
- numpy | |
- matplotlib | |
- seaborn | |
- pip | |
- pip: |
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 numpy as np | |
## Make a table of counts of each value in a numpy array. | |
# This returns the unique values and their counts in a numpy array. | |
x = np.array([1, 1, 1, 2, 2, 2, 7, 14, 2, 1]) | |
unique, counts = np.unique(x, return_counts=True) | |
print(np.asarray((unique, counts)).T) # Use transpose for better visual | |
## Sort it |
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
# Manual garbage collection due to limited RAM - useful in Kaggle competitions | |
import sys | |
for i in dir(): | |
if sys.getsizeof(eval(i)) > 10000: | |
print("the size of {} is:".format(i), sys.getsizeof(eval(i))/1e+9) | |
import gc | |
del train # delete a data frame | |
gc.collect() # manual garbage collection |
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
/* Basic viewing the structure commands */ | |
\c database_name --connect to a database. | |
\dt --view the tables. this filters out non-table relations. | |
\d --view the tables. Includes non-table relations. | |
\d tablename --view the columns of the table. | |
/* Create a table and import from a csv into that table. */ | |
CREATE TABLE employees ( | |
id SERIAL, |
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
#!/bin/sh | |
# Where I am storing useful sed commands for later use. | |
# Removing characters from a csv or text file. This removes a double-quote. | |
sed 's/"//g' filename.csv | |
sed 's/"//g' filename.csv > filename_new.csv | |
# Not sed, but using cut to remove columns of a csv file. | |
# This takes a pipe-delimited file and removes columns 2, 3, and 4. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
# From this problem on leetcode. | |
# https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/ | |
# Given an array of unique integers salary where salary[i] is the salary of the employee i. | |
# Return the average salary of employees excluding the minimum and maximum salary. | |
# Example: | |
# Input: salary = [4000,3000,1000,2000] |
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
/* | |
Given 2 tables in a MySQL database, Employee and Department, find the employees (including ties) with the highest | |
salaries for each department. | |
Employee table: | |
Id (auto incremented integer) | |
Name (Varchar, employee name) | |
DepartmentId (integer and key to Department table) | |
Salary (Integer) |
NewerOlder