Snippets

Small things that drove me nuts – and how they were resolved… an ever-expanding list, no doubt 🙂

 

 Issue

 Solution

 Source

plt.savefig() saves an empty picture or a cut-off picture plt.savefig() should be placed BEFORE plt.show() to prevent this happening  Stackoverflow solution
Pandas prints pie chart labels and a legend which is redundant To lose the legend: ct.plot.pie(“Submission”, legend = False)
Pandas prints pie chart labels and a legend which is redundant To lose the labels: ct.plot.pie(“Submission”, labels = None)
plt.legend(labels = ct.index)
 Stackoverflow solution
df.rename() with inplace = True gives a warning “A value is trying to be set on a copy of a slice from a DataFrame” Use a workaround:
my_data.columns = my_data.columns.str.replace(“OldName”, “NewName”)
Stackoverflow discussion and solutions
plt.imshow() distorts your image according to axis size There is a parameter to resolve this! plt.imshow(…, aspect = “auto”)
Image retrieved via Google static maps API is poor quality Use scale = 2 which retrieves e.g. 1280×1280 pixels for a 640×640 image Google developer documentation
get rid of column index levels from pivot df.columns.droplevel() resolves(…, aspect = “auto”) Stackoverflow solution
pandas list transform to multiple rows It’s a big snippet – head to stackexchange for the complete solution Stackoverflow solution

gizmogremlins

Comments are closed.

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: