Home > other >  Python pandas for 2 columns
Python pandas for 2 columns

Time:10-25

Want to value is the number of occurrences of certain combinations, in statistical df
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 statistics

CodePudding user response:

reference 1st floor JMZL response:
directly into a Python format strings, statistical

A little about how to operate, can in detail

CodePudding user response:

Do you want screening completely the same, or a line of a part of the same, such as grade and ranking does not include the same name

CodePudding user response:

reference JMZL reply: 3/f
do you want to screen completely the same, or a line of a part of the same, such as the grade and ranking does not include the same name

Filter to be completely the same, df groupby [r]. 'A', 'B' count () if can realize the function I want

CodePudding user response:

Micromsg
reference 4 floor response:
Quote: refer to the third floor JMZL response:
do you want to screen completely the same, or a line of a part of the same, such as the grade and ranking does not include the same name

Filter to be completely the same, df groupby [r]. 'A', 'B' count () if can realize the function I want

You put the whole structure into but he string structure can directly comparable
  • Related