I have a DataFrame that looks like:
import pandas as pd
df = pd.DataFrame(columns=['date', 'type', 'version'],
data=[
['2017-07-01', 'critical::issue::A', 'version1'],
['2017-07-01', 'critical::issue::A', 'version2'],
['2017-07-01', 'hardware::issue::B', 'version1'],
])
I'm returning the size of all the unique values for 'type' using the following;
sub_cat = ['critical::',
'hardware::',
'software::'
]
for cat in sub_cat:
x = df[df.type.str.startswith(cat)]
count = x.groupby('type').size()
if len(count) > 0:
print(count)
else:
print(cat, '0')
Results are correct but the output is sloppy:
type
critical::issue::A 2
dtype: int64
type
hardware::issue::B 1
dtype: int64
software:: 0
I'd like to format the output to make it more readable like the following example.
type
critical::issue::A 2
hardware::issue::B 1
software:: 0
Any suggestions?