Skip to content

Instantly share code, notes, and snippets.

@why-not
why-not / gist:4582705
Last active February 1, 2024 00:44
Pandas recipe. I find pandas indexing counter intuitive, perhaps my intuitions were shaped by many years in the imperative world. I am collecting some recipes to do things quickly in pandas & to jog my memory.
"""making a dataframe"""
df = pd.DataFrame([[1, 2], [3, 4]], columns=list('AB'))
"""quick way to create an interesting data frame to try things out"""
df = pd.DataFrame(np.random.randn(5, 4), columns=['a', 'b', 'c', 'd'])
"""convert a dictionary into a DataFrame"""
"""make the keys into columns"""
df = pd.DataFrame(dic, index=[0])
@why-not
why-not / shutdown-idle-aws.py
Last active March 4, 2024 19:29
Automatically stopping an AWS machine when users are not actively using a machine via ssh, and the CPU load avg over the past 5 mins is less than THRESHOLD. This will avoid getting billed for the machine when not in use (except ofcourse your storage will still be billed unless you delete everything and decommission those as well, which this scri…
#!/usr/bin/env python
# shell commands being automated.
# w
# aws ec2 stop-instances --instance-id INSTANCE_ID
"""
The script is the easy part, installing it into the unfriendly(imo) cron system and
making all the permissions and paths are set correctly is another issue altogether.
@why-not
why-not / stop-idle-azure-aws.py
Last active March 4, 2024 19:49
Automatically Shutting Down and Deallocating an AZURE or AWS VM (when idle AND no one is logged in via SSH)
#!/usr/bin/env python
# shell commands being automated.
# w
# aws ec2 stop-instances --instance-id INSTANCE_ID
# az vm deallocate --name NAME --resource-group RESOURCE_GROUP
"""
The script is the easy part, installing it into the unfriendly(imo) cron system and