More in the Source: https://stackoverflow.com/questions/3207219/how-do-i-list-all-files-of-a-directory
I found glob easier to select file of the same type or with something in common. Look at the following example:
import glob
txtfiles = []
for file in glob.glob("*.txt"):
txtfiles.append(file)
Using list comprehension
import glob
mylist = [f for f in glob.glob("*.txt")]
I find this very useful to find stuff in many directories, and it helped me finding a file about which I didn't remember the name:
import os
# Getting the current work directory (cwd)
thisdir = os.getcwd()
# r=root, d=directories, f = files
for r, d, f in os.walk(thisdir):
for file in f:
if ".docx" in file:
print(os.path.join(r, file))
https://www.cheatography.com/weidadeyue/cheat-sheets/jupyter-notebook/
jupyter nbconvert --to script yournotebook.ipynb
Time a cell:
%%time
Draw with Retina resolution:
%config InlineBackend.figure_format = 'retina'
import pandas as pd
res = pd.DataFrame(columns=('Time', '25%MAPE'))
slice1 = [{'Time':"24H", '25%MAPE':percentile(MAPEs,25)}]
res = res.append( slice1, ignore_index= True )
for property, value in vars(theObject).iteritems():
print property, ": ", value
import inspect
inspect.getmembers(TheClass, lambda a:not(inspect.isroutine(a)))