How can I get the correct numbers from this data in this table?


star

How can I do this?

result

from such data

data

what i did gives me a wrong answer

       A  A-  B  B+  B-  C  C+  C-  D  D+  D-  E  X  TOT
AGR    0   0  0   1   0  0   1   1  0   0   1  0  0    4
H/SC   0   0  1   0   0  1   0   0  0   0   2  0  0    4
CRE    0   0  0   1   0  0   0   1  1   1   0  0  0    4
GEO    0   0  1   0   0  0   1   0  0   0   2  0  0    4
CRE    0   0  0   0   0  0   0   0  0   0   2  0  0    2

My password

columns = ["A",'A-','B+',"B",'B-','C+',"C",'C-','D+',"D",'D-',"E",'X']
            sub_lists = list(df1[column_list])
            sub_lists = pd.Series(sub_lists)
            #print(sub_lists)
            agr = (pd.crosstab(sub_lists, df1['AGR'], margins=True,       margins_name='TOTAL').iloc[:,:-1].reindex(columns, axis=1, fill_value=0).rename_axis(None))
            cre = (pd.crosstab(sub_lists, df1['CRE'], margins=True, margins_name='TOTAL').iloc[:,:-1].reindex(columns, axis=1, fill_value=0).rename_axis(None))
            geo = (pd.crosstab(sub_lists, df1['GEO'], margins=True, margins_name='TOTAL').iloc[:,:-1].reindex(columns, axis=1, fill_value=0).rename_axis(None))
            hsc = (pd.crosstab(sub_lists, df1['H/SC'], margins=True, margins_name='TOTAL').iloc[:,:-1].reindex(columns, axis=1, fill_value=0).rename_axis(None))
            bst = (pd.crosstab(sub_lists, df1['BST'], margins=True, margins_name='TOTAL').iloc[:,:-1].reindex(columns, axis=1, fill_value=0).rename_axis(None))

            c = pd.concat([agr, cre,geo,hsc,bst], axis=1, join='inner')
            d = c.groupby(lambda x:x, axis=1).sum()
            d['TOT'] = d[columns].sum(axis=1)

STREAM  ADM NAME    KCPE    GEO CRE H/SC    AGR BST
EAGLE   231 MITCHEL     279 D   D+  E   D-  B
EAGLE   322 BEATRICE 268    E   C-  E   D+  C
HAWK    654 BERYL   344 A   C-  E   A-  C
EAGLE   335 SOFI    266 E   C-  E   D   C
HAWK    321 LOICE   319 E   D+  C-  B   A-

HAWK 234 BETTY 284 E D-

Jesler

Your solution is changed by 2 columns , then used with , for removing the last row, not the last column, adding the missing categories, dropping the index and column names ( , ) one last time, by :DataFrame.meltDataFramecrosstabiloc.iloc[:-1]DataFrame.reindexvariablevalueDataFrame.rename_axis

columns = ["A",'A-','B+',"B",'B-','C+',"C",'C-','D+',"D",'D-',"E",'X']

cols = ['AGR','CRE','GEO','H/SC','BST']
df1 = df[cols].melt()

df2 = (pd.crosstab(df1['variable'], df1['value'], margins=True, margins_name='TOTAL')
        .iloc[:-1]
        .reindex(columns + ['TOTAL'], fill_value=0, axis=1)
        .rename_axis(index=None, columns=None))
print (df2)
      A  A-  B+  B  B-  C+  C  C-  D+  D  D-  E  X  TOTAL
AGR   0   1   0  1   0   0  0   0   1  2   1  0  0      6
BST   0   2   0  1   0   0  3   0   0  0   0  0  0      6
CRE   0   0   0  0   0   0  0   3   2  0   1  0  0      6
GEO   1   0   0  0   0   0  0   0   0  1   0  4  0      6
H/SC  0   0   0  0   0   0  0   1   0  0   0  5  0      6

Related


How can i get data from table in MVC

username I have aspx page. I assign the data to the table. How to get new value from this table in Controller. Or another way how to generate tables/tables in ASPX pages in MVC? <table id="Products" class="Products"> <tr> <th>ProductId</th>

How can i get data from table in MVC

username I have aspx page. I assign the data to the table. How to get new value from this table in Controller. Or another way how to generate tables/tables in ASPX pages in MVC? <table id="Products" class="Products"> <tr> <th>ProductId</th>

how can i get data in table/td

Dorbania I am using below code to get cell value. alert(document.getElementById("table-body-positions").rows[0].cells[3].innerHTML); Td value is <td><a data-action="details"><span><span class="">2019/01/04 13:36:19</span></span></a></td> I get this result. <

how do i get data from the table

Ruben Can someone assist me how to get data from a table in Excel 2013? I have a table called Personal: I want to have a control in a cell like this: (I don't know how to add this control in a cell) So I can select data from the table: I googled a lot before a

how do i get data from the table

Ruben Can someone assist me how to get data from a table in Excel 2013? I have a table called Personal: I want to have a control in a cell like this: (I don't know how to add this control in a cell) So I can select data from the table: I googled a lot before a