-
Keywords: #books #mentalhealth #life
-
Age limit: 120 (cell regeneration stops)
-
5 Blue Zones in the World (the geographic regions where people live longest)
-
There's no word that means "retire" in Japanese
-
Diet, exercise, finding a purpose in life, forming strong social ties
-
1800-1900 calories per day (eat only 80%)
This file contains hidden or 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
| # List unique values in a DataFrame column | |
| pd.unique(df.column_name.ravel()) | |
| # Convert Series datatype to numeric, getting rid of any non-numeric values | |
| df['col'] = df['col'].astype(str).convert_objects(convert_numeric=True) | |
| # Grab DataFrame rows where column has certain values | |
| valuelist = ['value1', 'value2', 'value3'] | |
| df = df[df.column.isin(valuelist)] |
This file contains hidden or 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
| if any(bad in name for bad in NOT_ALLOWED): | |
| raise ValueError("'name' may not contain any of {}".format(NOT_ALLOWED) | |
| if not all(isinstance(val, int) for val in DATA) or len(DATA) !=2: | |
| raise ValueError("'DATA' must consist of 2 ints") |
This file contains hidden or 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
| dict([[h.partition(':')[0], h.partition(':')[2]] for h in rawheaders.split('\n')]) |
This file contains hidden or 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 requests # just a choice of comfort for me | |
| def download(url_address, filename): | |
| response = requests.get(url_address, stream=True) | |
| response.raise_for_status() | |
| with open(filename, "wb") as f: | |
| total_length = response.headers.get('content-length') | |
| if total_length is None: | |
| f.write(response.content) | |
| else: | |
| total_length = int(total_length) |
This file contains hidden or 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 pandas as pd | |
| df = pd.DataFrame({'AAA' : [4,5,6,7], 'BBB' : [10,20,30,40],'CCC' : [100,50,-30,-50]}); df | |
| ''' | |
| AAA BBB CCC | |
| 0 4 10 100 | |
| 1 5 20 50 | |
| 2 6 30 -30 | |
| 3 7 40 -50 | |
| ''' |
This file contains hidden or 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/env python3.0 | |
| import sys, array, tempfile, heapq | |
| assert array.array('i').itemsize == 4 | |
| def intsfromfile(f): | |
| while True: | |
| a = array.array('i') | |
| a.fromstring(f.read(4000)) | |
| if not a: |
This file contains hidden or 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 pandas as pd | |
| df = pd.read_csv(r'data.csv', encoding='utf8') | |
| df['score'] = df['score'].str.replace('%', '') | |
| score_df = (df['score'].sort_values(ascending=False)[:5]) | |
| indexes = score_df.index | |
| print (df.iloc[indexes]) |
This file contains hidden or 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
| def get_file_md5(f, chunk_size=8192): | |
| h = hashlib.md5() | |
| while True: | |
| chunk = f.read(chunk_size) | |
| if not chunk: | |
| break | |
| h.update(chunk) | |
| return h.hexdigest() |
This file contains hidden or 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 os, time | |
| import threading, Queue | |
| class WorkerThread(threading.Thread): | |
| """ A worker thread that takes directory names from a queue, finds all | |
| files in them recursively and reports the result. | |
| Input is done by placing directory names (as strings) into the | |
| Queue passed in dir_q. |