Reputation: 473
l have a column in pandas dataframe called Column_values
. l want to make a histogram on these values as follow :
alphabetic characters
alpha numeric chacaters
digits and special chars , ; / .
Here is my column
Column_values
hello
goodmorning
6,35
11,68
Yours
ok
2292
Question
number
those
937,99
and
1
620
amounts
ROB21
Pieces
designation
these
rates
13s
2
with
the
Thank you
Upvotes: 1
Views: 154
Reputation: 2944
First, you need to create the group using a mapping function and then plot the histogram. The function is mapping by condition - in your case:
def find_group(val):
val = str(val)
if val.isalpha():
return 'Alpha'
elif val.isalnum and any(c.isalpha() for c in val):
return 'Alphanumeric'
else:
return 'Special'
the transformation is by using pandas apply method:
df.Column_values.apply(find_group)
and the plotting is by adding value_counts and plot methods:
df.Column_values.apply(find_group).value_counts().plot(kind='bar')
Upvotes: 1