小编cbc*_*cbd的帖子

Pandas change order of columns in pivot table

The representation of pivot tabel not looks like something I looking for, to be more specific the order of the resulting rows. I can`t figure out how to change it in proper way.

Example df:

test_df = pd.DataFrame({'name':['name_1','name_1','name_1','name_2','name_2','name_2','name_3','name_3','name_3'], 
                        'month':[1,2,3,1,2,3,1,2,3], 
                        'salary':[100,100,100,110,110,110,120,120,120], 
                        'status':[1,1,2,1,1,3,2,2,1]})
Run Code Online (Sandbox Code Playgroud)

code for make pivot:

test_df.pivot_table(index='name', columns=['month'], 
             values=['salary', 'status'])
Run Code Online (Sandbox Code Playgroud)

Actual output:

       salary           status      
month       1    2    3      1  2  3
name                                
name_1    100  100  100      1  1  2
name_2    110  110  110      1  1  3
name_3    120  120  120      2 …
Run Code Online (Sandbox Code Playgroud)

pivot-table pandas

5
推荐指数
2
解决办法
361
查看次数

Pandas将值与前一行的过滤条件进行比较

我有一个DataFrame,其中包含有关员工薪水的信息.它大约有900000多行.

样品:

+----+-------------+---------------+----------+
|    |   table_num | name          |   salary |
|----+-------------+---------------+----------|
|  0 |      001234 | John Johnson  |     1200 |
|  1 |      001234 | John Johnson  |     1000 |
|  2 |      001235 | John Johnson  |     1000 |
|  3 |      001235 | John Johnson  |     1200 |
|  4 |      001235 | John Johnson  |     1000 |
|  5 |      001235 | Steve Stevens |     1000 |
|  6 |      001236 | Steve Stevens | …
Run Code Online (Sandbox Code Playgroud)

python compare rows dataframe pandas

3
推荐指数
1
解决办法
396
查看次数

标签 统计

pandas ×2

compare ×1

dataframe ×1

pivot-table ×1

python ×1

rows ×1