import
numpy as np
import
pandas as pd
car_brand
=
np.array([
"bmw"
,
"bmw"
,
"bmw"
,
"bmw"
,
"benz"
,
"benz"
,
"bmw"
,
"bmw"
,
"benz"
,
"benz"
,
"benz"
,
"benz"
,
"bmw"
,
"bmw"
,
"bmw"
,
"benz"
,
"benz"
, ], dtype
=
object
)
version
=
np.array([
"one"
,
"one"
,
"one"
,
"two"
,
"one"
,
"one"
,
"one"
,
"two"
,
"one"
,
"one"
,
"one"
,
"two"
,
"two"
,
"two"
,
"one"
,
"two"
,
"one"
],
dtype
=
object
)
fuel_type
=
np.array([
"petrol"
,
"petrol"
,
"petrol"
,
"diesel"
,
"diesel"
,
"petrol"
,
"diesel"
,
"diesel"
,
"diesel"
,
"petrol"
,
"petrol"
,
"diesel"
,
"petrol"
,
"petrol"
,
"petrol"
,
"diesel"
,
"diesel"
, ], dtype
=
object
)
year_release
=
np.array([
2000
,
2005
,
2000
,
2007
,
2000
,
2005
,
2007
,
2005
,
2005
,
2000
,
2007
,
2000
,
2007
,
2005
,
2005
,
2007
,
2000
],
dtype
=
object
)
cross_tab_data
=
pd.crosstab(index
=
car_brand,
columns
=
[version, fuel_type, year_release],
rownames
=
[
'car_brand'
],
colnames
=
[
'version'
,
'fuel_type'
,
'year_release'
])
barplot
=
cross_tab_data.plot.bar()
stacked_data
=
cross_tab_data.stack(level
=
1
)
barplot
=
stacked_data.plot.bar()
stacked_data
=
cross_tab_data.stack(level
=
2
)
barplot
=
stacked_data.plot.bar()