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
%%time | |
# np.vectorize: large dataframe | |
dfY = pd.DataFrame() | |
dfY["x"], dfY["y"], dfY["z"] = np.vectorize(myfunc4)(dfL.B, dfL.C) | |
display(dfY.tail()) |
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
%%time | |
# list comprehension | |
xyz = [myfunc4(b, c) for b, c in zip(dfL.B, dfL.C)] | |
dfY = pd.DataFrame(xyz, columns=["x", "y", "z"]) | |
display(dfY.tail()) |
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
%%time | |
# dictionary comprehension | |
xyz = {i: myfunc4(b, c) for i, b, c in zip(dfL.index, dfL.B, dfL.C)} | |
dfY = pd.DataFrame.from_dict(xyz, orient="index", columns=["x", "y", "z"]) | |
display(dfY.tail()) |
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
%%time | |
# convert df to dictionary before iterating | |
dictL = dfL.to_dict(orient="records") | |
for row in dictL: | |
res = myfunc2a(row) | |
dfY = pd.DataFrame.from_dict(dictY).T | |
dfY.columns = ["x", "y", "z"] | |
display(dfY.tail()) |
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
%%time | |
# apply - zip - large dataframe | |
dfY = pd.DataFrame() | |
dfY["x"], dfY["y"], dfY["z"] = zip(*dfL.apply(lambda x: myfunc4(x["B"], x["C"]), axis=1)) | |
display(dfY.tail()) |
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
%%time | |
# apply, large dataframe | |
dfY = pd.DataFrame() | |
dfY[["x", "y", "z"]] = dfL.apply(lambda x: myfunc4(x["B"], x["C"]), axis=1, result_type="expand") | |
display(dfY.tail()) |
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
%%time | |
# itertuples: large dataframe | |
dictY = dict() | |
for row in dfL.itertuples(): | |
res = myfunc2(row) | |
dictY[row] = list(res) | |
dfY = pd.DataFrame() | |
dfY = pd.DataFrame.from_dict(dictY).T | |
dfY.columns = ["x", "y", "z"] |
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
%%time | |
# list comprehension: almost as good as vectorization | |
xyz = [myfunc4(b, c) for b, c in zip(dfS.B, dfS.C)] | |
dfY = pd.DataFrame(xyz, columns=["x", "y", "z"]) | |
display(dfY.tail()) |
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
%%time | |
# runner-up: dictionary comprehension | |
xyz = {i: myfunc4(b, c) for i, b, c in zip(dfS.index, dfS.B, dfS.C)} | |
dfY = pd.DataFrame.from_dict(xyz, orient="index", columns=["x", "y", "z"]) | |
display(dfY.tail()) |
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
%%time | |
# np.vectorize: rehabilitated | |
dfY = pd.DataFrame() | |
dfY["x"], dfY["y"], dfY["z"] = np.vectorize(myfunc4)(dfS.B, dfS.C) | |
display(dfY.tail()) |
NewerOlder