Binned data with pandas value_count() sends Error: Endstream has been closed

Hello,
If you ran this code in Grasshopper python, you would get EndOfStreamException error.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

idx = pd.Index([21, 13, 33,36, 40,44, 50, 18, 50, 14])
idx_bins = [10, 20, 30, 40, 51]
binned_idx = pd.cut(idx,idx_bins,right = False)

prob = binned_idx.value_counts().plot(kind='bar')
plt.show()

I figured the issue is with this line:

prob = binned_idx.value_counts().plot(kind='bar')

Once binned_idx is replaced with idx, the issue is resolved.
But that would not give us the graph of binned_idx,

Thanks,
Clive