1
많은 ipython/jupyter 노트북에서 실행되는 데이터 분석 프로젝트를 요약하려고하며 각 노트북은 상당히 길다. 이 과정을 도울 수있는 것들 중 하나는 적어도 전반적인 "입력"절임이 들어가고 "출력"절임이 나간다는 것입니다.ipython/jupyter 노트북에서 들어오고 나가는 피클을 추출하는 방법
가장 깨끗하고/가장 빠르고 효율적인 방법은 무엇입니까?
많은 ipython/jupyter 노트북에서 실행되는 데이터 분석 프로젝트를 요약하려고하며 각 노트북은 상당히 길다. 이 과정을 도울 수있는 것들 중 하나는 적어도 전반적인 "입력"절임이 들어가고 "출력"절임이 나간다는 것입니다.ipython/jupyter 노트북에서 들어오고 나가는 피클을 추출하는 방법
가장 깨끗하고/가장 빠르고 효율적인 방법은 무엇입니까?
은 내가 그것을 할 수있는 가장 좋은 방법이 있는지 확실하지 않습니다,하지만 ... 적어도 하나의 방법
def summerize_pickles(notebook_path):
from IPython.nbformat import current as nbformat
import re
with open(notebook_path) as fh:
nb = nbformat.reads_json(fh.read())
list_of_input_pickles = []
list_of_output_pickles = []
for cell in nb["worksheets"][0]["cells"]:
# This confirms there is at least one pickle in it.
if cell["cell_type"] != "code" or cell["input"].find("pickle") == -1: # Skipping over those cells which aren't code or those cells with code but which don't reference "pickle
continue
# In case there are multiple lines, it iterates line by line.
for line in cell["input"].splitlines():
if line.find("pickle") == -1: # Skips over lines w/ no mention of "pickle" to potentially reduce the number of times it's searched.
continue
############################ ############################ ############################ ############################
code_type = str()
if line.find("pickle.dump") != -1 or line.find(".to_pickle")!= -1:
code_type = "output"
elif line.find("pickle.load") != -1 or line.find(".read_pickle")!= -1:
code_type = "input"
else:
continue # This tells the code to skip over lines like "import cpickle as pickle"
############################ ############################ ############################ ############################
filename = re.findall(r'"(.*?)"', line) # This gets all the content between the quotes. See: http://stackoverflow.com/questions/171480/regex-grabbing-values-between-quotation-marks
############################ ############################ ############################ ############################
if code_type == "input":
list_of_input_pickles.append(filename[0])
elif code_type == "output":
list_of_output_pickles.append(filename[0])
pickles_dict = {"input_pickles":list_of_input_pickles,
"output_pickles":list_of_output_pickles }
return pickles_dict
이 피클에 도움이되지 않습니다하지만이 구조를보고에 도움이 되나요 노트 : Calico Tools 및 기타 응답을 확인하십시오. http://stackoverflow.com/questions/24895714/is-it-possible-to-create-grouping-of-input-cells-in-ipython-notebook – Afflatus