l有csv
文件,该文件与pandas
一起处理。该列被称为manual_raw_value
我想检索此列中的唯一字符并制作histogram
。使用映射函数在pandas列中绘制直方图
检索所有不重复值L做了以下内容:
unique_values = set(df.manual_raw_value.apply(list).sum())
{' ',
'!',
'"',
'%',
'&',
"'",
'(',
')',
'*',
'+',
',',
'-',
'.',
'/',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
':',
'=',
'>',
'?',
'@',
'_',
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z'}
下面是数据
manual_raw_value
6,35
11,68
VOTRE
AVEL AR VRO
2292
questions.
nb
les
937,99
à
et
TTC
1
620
Echéance
vos
ROB21
Pièce
AGRIAL
désignation
des
taux
13s
2
par
le
mois,
32
21/07/2016
FR
au
0
téléphonique
BROYEUR
et
ST
TVA
de
des
ECHEANCIER
à
ne
lieu
481,67
N°0016
de
ministère
de
20/11/2015
Si
vous
59
cas
EUR
3.19
2
contrôle
assurances
BAS
et
4423873
renseignements
6104219
C9DECOMPTEDIVERS
6635
DE
10825
现在,由于L具有unique values
升要打个histgram。 这里是欧莱雅已经试过
import pandas as pd
def find_group(val):
unique_values = set(df.manual_raw_value.apply(list).sum())
for unique in unique_values:
# get the number of occurence of all the unique values
# then make a histogram
df = pd.read_csv('words.csv',sep=',')
df = df.astype(str)
df.manual_raw_value=df.manual_raw_value.str.lower()
df.manual_raw_value.apply(find_group)
df.manual_raw_value.apply(find_group).value_counts().plot(kind='bar')
的唯一值是那些由函数 unique_values = set(df.manual_raw_value.apply(list).sum())
这是{' ', '!', '"', '%', '&', "'", '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', .....
等返回。 现在来看例如在手动row values : 6,35 11,68
两个值那么我们可以说1 appears twice 6 twice ',' twice 3 one time 5 one time
编辑-1 我企图此代码来使alpha cells
occurence的numbre的直方图,alpahnumeric
细胞和special char cells
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'
df.Column_values.apply(find_group)
df.Column_values.apply(find_group).value_counts().plot(kind='bar')
现在升想使一个直方图在人物等级:
通过循环遍历每个单元格来获取列中的唯一字符。 (完成)
计算这些字符在所有单元格中出现的次数并生成直方图。 #1获得stucked它 - 一旦
编辑-2 让我们举一个实际的例子。比方说,我的专栏叫做Column_value
Column_value
hello
good
morning
how
are
you
1,在每列L计算每个字符
hello : h=1 l=2 o=1 e=1
good : g=1 o=2 d=1
morning : m=1 o=1 r=1 n=2 g=1
how: h=1 o=1 w=1
are : a=1 r=1 e=1
you: y=1 o=1 u=1
2-发生的数量进行求和得到的每个字符的出现次数在所有行
h=1+1=2
l=2
o=2+1+1+1=5
e=1+1=2
g=1
d=1
等 现在,使 H = 2,L = 2的直方图,O = 5,E = 2,G = 1,d = 1
@ImportanceOfBeingErnest,请参阅我的更新。我想通过循环单元格来计算该列中每个字符的出现次数,然后制作一个直方图 – vincent75
@ImportanceOfBeingErnest,请参阅更新2的实际示例 – vincent75
@ vincent75我想你不想要直方图的唯一值,然后直方图总是1. – suvy