Home > other >  Datafram how multiple choice classification sorting statistics
Datafram how multiple choice classification sorting statistics

Time:09-19


The each line has a variety of abd acf bf how multiple choice classification statistics?
How many every industry the question a how many d
Each way of controlling this problem a few a
Tried all sorts of is how much a return how many abd acf like this,,

Seek help from a great god,,,

CodePudding user response:

Didn't understand what are you going to do

CodePudding user response:

reference 1st floor cool_sql_9 response:
didn't understand what you want to do

Data is a lot of companies questionnaire survey data,,,
The first column is the second column is the industry way of holding the abcd each subject their answers are those
Want to statistics a how many of each subject of different industries, and how many b,,,

CodePudding user response:

 
Lista=[' c ', 'b', 'c', 'b', 'ABC' and 'abd', 'acd', 'abd', 'acd]
Dictb={}
For lista1 in lista:
If dictb. Get (lista1, "FFF")=="FFFF" :
Dictb [lista1]=1
The else:
Dictb [lista1] +=1
Print (dictb)

CodePudding user response:

. 
Lista=[' c ', 'b', 'c', 'b', 'ABC' and 'abd', 'acd', 'abd', 'acd]
Dictb={}
For lista1 in lista:
If dictb. Get (lista1, "FFF")=="FFF" :
Dictb [lista1]=1
The else:
Dictb [lista1] +=1
Print (dictb)
Print (lista)

CodePudding user response:

 
Lista=[' c ', 'b', 'c', 'b', 'ABC' and 'abd', 'acd', 'abd', 'acd]
Dictb={}
For lista1 in lista:
For _, lista2 enumerate in (lista1) (list) :
If dictb. Get (lista2, "FFF")=="FFF" :
Dictb [lista2]=1
The else:
Dictb [lista2] +=1
Print (dictb)
Print (lista)


All is decomposed into the radio

CodePudding user response:

I have done some custom data, do the test, the following is a code, combined with their own data you try
The from the collections import Counter
# read data
data=https://bbs.csdn.net/topics/pd.read_excel (r 'C: \ Users \ Desktop \ TTT XLSX')
Each line # the answer to all questions stitching together
Data [' summary ']=data. The apply (lambda x: np. Sum (x) [5], the axis=1)
# need only select columns
Data1=data [[' industry ', 'control', 'summary']]

# custom function of letters to count
Def f (x) :
Ll=[c.l power () for c x in the if c.i salpha ()]
Return Counter (ll)
Counter=data1 [' summary ']. The map (f)

# convert letters count dictionary to DataFrame
Counterdf=pd. DataFrame ()
Counterdf=counter. The map (lambda x: dict (x))
Counterdf1=pd. DataFrame (list (counterdf. Values))
Count part # letters with source data splicing
Df_final=pd. Concat ([data1, counterdf1], axis=1) [[' industry ', 'control', 'a', 'b', 'c', 'd']]

  • Related