You are invited to Log in or Register a free Frihost Account!

Blog around the clock

Created on Wed Dec 14, 2011 1:39 pm with 182 blog posts
The is my blog on Frihost. I probbaly don't blog around the clock, but hopefully more than 1 post per life time. My typical areas of interest: project management, & software development.

Jupyter: Plotting pivots & changing legend entries in python with 1 comments on Thu Feb 15, 2018 5:55 pm
A while ago I blogged about project Jupyter and in the last days I have been working a lot with it and I am still fascinated by its power.

Today I faced and solved two challenges I like to share here:
. plotting a pivot table
. changing legend entries

Assume we have the following dataframe:

Creating a pivot is a piece of cake by using the pandas pivot_table method on that dataframe:

pivot = pd.pivot_table(df,index=["Org"],values=["Male employees","Female employees"],


This gets us
. the number of departments per org ( = len Female employees or len Male employees )
. the sum of male and female employees per org ( = sum Female employees and sum Male employees )
. as well as mean, min and max

How to plot ?
We can simply save the pivot tables as a new dataframe 'pivot' and call its plot method. Let's say we want to plot sum of male and female employees per org. First we need to drop the other statistics from the pivot table we don't need for the plot. Then we plot:


Only problem here is that the legend entries of this plot look a bit cryptic. Here is some code to fix this:

ax = plt.gca()
handles,labels = ax.get_legend_handles_labels()
new_labels = []
for l in labels:
ax.legend(handles, new_labels)

I have shared the entire notebook here.
Linux Lite: Some Power Manager Tweaks in linux with 0 comments on Wed Jan 24, 2018 2:51 pm
On my shiny new Linux Lite installation I noticed:
* no battery status indicator in the system tray
* sleep button did not do anything

I started the Xfce Power Manager ( after figuring out that Linux Lite is using Xfce as GUI ) and made changes highlighted below:

* changed behavior of sleep and hibernate buttons
* ticked on system tray icon to appear

I also noticed that under the 'Security' Tab 'Lock screen when system is going to sleep' is not turned on, which I changed since I think this is a real security exposure.
How to print ipython notebooks w/o source code in python with 0 comments on Fri Jan 19, 2018 12:34 pm
This is something I really need to create sort of standard reports based on ipython notebooks which should not contain the source code and input prompts of ipython cells: the capability to print ipython notebooks without the source code.

There are ways to do that as discussed here on stackoverflow but all these methods involve adding some ugly code to your ipython cells or tweaking the way the ipython server is started ( or running nbconvert ) which might be out of your control if you use some cloud offering like Data Science Experience on IBM Cloud and not your own ipython installation.

Here is how I achieve this: I simply download my notebook as html. Then I run this python script to convert that html file so that prompts and code cells are gone:

FILE = "/somewhere/myHTMLFile.html"

with open(FILE, 'r') as html_file:
    content =

# Get rid off prompts and source code
content = content.replace("div.input_area {","div.input_area {\n\tdisplay: none;")   
content = content.replace(".prompt {",".prompt {\n\tdisplay: none;")

f = open(FILE, 'w')

That script bascially adds the CSS ‘display: none’ attribute for all divs of class ‘prompt’ or ‘input_area’.

That tweaked html page now easily can be printed into a pdf file for me to get my standard report without any code or input prompt cells.

If you know what you are doing you can add more CSS tweaking, like e.g. this one, to that Python code:

# For dataframe tables use Courier font family with smaller font size
content = content.replace(".dataframe thead","table.dataframe { font-size: 7px; font-family: Courier;  }\n.dataframe thead")

To figure out things like that I used Firefox Inspector to determine class names of DOM elements ( like e.g. 'div.data_frame' is used to display dataframe tables in ipython ) and some CSS knowledge to achieve the manipulations I find useful, like reducing the font size of tables in order to make them fit on pages printed with portrait orientation.
Time is Money ? in culture with 3 comments on Wed Jan 03, 2018 9:24 am
This morning I was listening to an interview with Eckart von Hirschhausen, a German physician and comedian, in my favorite morning radio show.

He brought up a valid point: the saying "Time is Money" is certainly not true. Simply consider this: you can gain more and more money, but your time is limited. Thus: time is much more valuable than money

If you look at your calendar at the beginning of the year it hopefully looks quiet blank yet. He came up with the idea to not create any dates in your calendar which would make you feel relieved if that date would go away later on.
Searching like a Pro in Google Chrome in browser with 0 comments on Sun Dec 31, 2017 5:44 pm
It took me a while to figure out how to search like a Pro in Google Chrome. In Firefox I am used to the search drop down box where you can type in a search phrase and then select a search engine.
In Chrome it works in a different way. You can manage search engines under Options and assign keywords to those, like e.g. 'maps' for Google Maps or 'fb' for Facebook.
Then in the address bar you type that keyword followed by a white space, then your search phrase. And voilà, a search for that phrase is performed by the search engine of your choice !
--> All blog posts (182)

© 2005-2011 Frihost, forums powered by phpBB.