0

data looks like this:

enter image description here

 col1  col2
 1     med
 1     low
 1     high
 2     high
 3     low
 2     high
 3     low

there is two columns, i want to group col2 and count each item in col1, e.g. how many ones and twos have 'maRali' feature.

used get_dummies to convert categorical variables to numeric, but while plotting get error:

TypeError: 'DataFrame' objects are mutable, thus they cannot be hashed

here is the whole code:

import matplotlib.pyplot as plt
import numpy as np

import pandas as pd

data = data = pd.read_csv(r"C:\Users\givi.jalaghania\.spyder-py3\07_maragebi.csv")

to_numeric = pd.get_dummies(data['riskiaobis done'])


ct = ['datvla']


# data.groupby(ct).agg('count').plot(kind = 'bar')


data.groupby(ct, to_numeric).size()
Anurag Dabas
  • 23,866
  • 9
  • 21
  • 41
jalaghania
  • 11
  • 2
  • Problem is in `data.groupby(ct, to_numeric).size()` - what should do this code? How looks column `riskiaobis done` in sample data? – jezrael Jul 09 '21 at 06:26

1 Answers1

0

I think here is possible use crosstab:

pd.crosstab(data['col1'], data['col2']).plot(kind = 'bar')
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
  • @jalaghania - check [this](https://stackoverflow.com/questions/28931224/adding-value-labels-on-a-matplotlib-bar-chart) – jezrael Jul 09 '21 at 06:49