For example, df=
Name grade ranked
A grade 1 1 name
A second grade 1
C grade 2,,
D,,,,
E,,,,
All the columns will have duplicate values, and all the value of the column length is not fixed,
Now to statistics and three columns of the value of the line, the number of occurrences of,
Such as: A grade 1 first how many times the line sequence appeared,
A second grade 1 how many times the line sequence appeared,
So on,
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
I use the following method,
To combine three columns into a dataframe first, and then use df2=pd. Value_count (df1/column 1) calculate the repeat item in column 1,
Get the following format:
Column 1
Aa 3
Bb 4
Cc 5
But the above 2 columns is a common column (column 1) series,
Now want to turn it into 2 columns [' aa ', 'bb', 'cc'] and [1, 2, 3], again for the 2 column to column names,
Seek advice on how to become a great god 2 columns, or * at the above, there are three columns will better way, please show
Pay attention to aa, bb, cc, and the content of the length of the Numbers 1, 2, 3 is not fixed, for example here into a fixed length and content of the special case,
CodePudding user response:
Directly into a Python format strings, carries on the statisticsCodePudding user response: