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
for k,v in sorted(foo.items()): | |
print k, v | |
for k in sorted(foo.keys()): | |
print k, foo[k] | |
More at: https://stackoverflow.com/questions/364519/in-python-how-do-i-iterate-over-a-dictionary-in-sorted-key-order |
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 json | |
with open('json_file.json') as f: | |
data = json.load(f) | |
print(data) |
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
""" | |
y2k | |
19016 -> 01/23/2020 | |
0 = 12/31/1967 | |
1 = 01/01/1968 | |
""" | |
import sys | |
from datetime import datetime, timedelta |
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
curl https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python - | |
# Silent version | |
#curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | 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
p 15count_coverage.py 2>&1 | tee out.txt |
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
nme = ["aparna", "pankaj", "sudhir", "Geeku"] | |
deg = ["MBA", "BCA", "M.Tech", "MBA"] | |
scr = [90, 40, 80, 98] | |
# New from dictionary | |
dict = {'name': nme, 'degree': deg, 'score': scr} | |
df = pd.DataFrame(dict) | |
clean_df.to_csv(OUTPUT_FILENAME, index=False) | |
# New dataframe from subset of pandas dataframe |
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
# Histogram of words per document in the first page | |
import matplotlib.pyplot as plt | |
plt.style.use("ggplot") | |
plt.hist([s for s in words_per_doc], bins=10) | |
plt.xlabel('Documents') | |
plt.ylabel('Number of words') | |
plt.show() |
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
df = pd.read_csv(FILENAME, names=["id", "title", "text"], | |
escapechar='\\', encoding='utf-8', header=0) | |
print(df.describe()) # Summary statistics (count, unique, top, freq) for every column of the dataframe | |
print(df.info()) # Information about each column on the dataframe, and memory usage | |
print(df.head()) # Show first 5 rows of dataframe | |
print(df.head(3)) # Show first 3 rows of dataframe | |
# Head with only a few columns, with random sampling of 10 rows |
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
#!/usr/bin/python | |
import subprocess | |
import re | |
# Get process info | |
ps = subprocess.Popen(['ps', '-caxm', '-orss,comm'], | |
stdout=subprocess.PIPE).communicate()[0].decode() | |
vm = subprocess.Popen(['vm_stat'], stdout=subprocess.PIPE).communicate()[ | |
0].decode() |
NewerOlder