小编Bod*_*de 的帖子

索引错误:索引 1491188345 超出轴 0 的范围,大小为 1491089723

我有一个数据框,df,有 646585 行和 3 列,看起来像:

index      inp       aco         count                
  0       2.3.6.   dp-ptp-a2f   22000
  1       2.3.12.  ft-ptp-a2f   21300
  2       2.5.9.   dp-ptp-a2f   21010
  3       0.8.0.   dp-ptp-a4f   20000
  4       2.3.6.   ft-ptp-a2f   19000               
  5       2.3.6.   ff-ptp-a2f   18500        
  ...                            ...
  ...                            ...   
  ...                            ...                 
Run Code Online (Sandbox Code Playgroud)

我尝试使用以下代码透视数据框:

df1=df.pivot_table(values='count', index='inp', columns='aco',fill_value=0)
print(df1)
Run Code Online (Sandbox Code Playgroud)

但我得到了

IndexError: index 1491188345 is out of bounds for axis 0 with size 1491089723
Run Code Online (Sandbox Code Playgroud)

python pivot-table dataframe pandas

8
推荐指数
1
解决办法
2108
查看次数

熊猫value_counts()降序排列

有一个数据框,df

Index              Date               Name         Category
 0            2017-08-09              ABC-SAP       1
 1            2017-08-09              CDE-WAS       2
 2            2017-08-10              DEF           3
 3            2017-08-11              DEF           3
 4            2017-08-11              CDE-WAS       2
 5            2017-08-11              CDE-WAS       2
Run Code Online (Sandbox Code Playgroud)

我执行了以下代码:

df2=pd.DataFrame(df, columns= ['Name','Category'])
df2= df['Name'].groupby(df['Category']).value_counts()
print(df2)
Run Code Online (Sandbox Code Playgroud)

然后我得到:

 Index             Name
 (1,ABC-SAP)       1              
 (2,CDE-WAS)       3                         
 (3,DEF)           2             
Run Code Online (Sandbox Code Playgroud)

value.counts()不会在NAME列上返回降序。我真的希望按从高到低的降序排列。有什么办法吗?

python pandas

5
推荐指数
1
解决办法
4032
查看次数

按星期几进行分组 pandas

  I have a dataframe,df 

        Index       eventName Count   pct
     2017-08-09       ABC     24     95.00%
     2017-08-09       CDE    140     98.50%
     2017-08-10       DEF    200     50.00%
     2017-08-11       CDE    150     99.30%
     2017-08-11       CDE    150     99.30%
     2017-08-16       DEF    200     50.00%
     2017-08-17       DEF    200     50.00%
Run Code Online (Sandbox Code Playgroud)

我想通过计算 pct 列中的值来按每日每周发生次数进行分组。例如,我们现在有:

 2017-08-09 has 2 values in pct column  and  2017-08-16 has 1 value in pct, then we have Monday:3 
  2017-08-10  has 1 value and 2017-08-17 has 1 value,then we have Tuesday:2 and so on
Run Code Online (Sandbox Code Playgroud)

那么生成的数据框应该如下所示:

    Index        Count   
 Monday            3
 Tuesday           2
 Wednesday …
Run Code Online (Sandbox Code Playgroud)

python pandas

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

标签 统计

pandas ×3

python ×3

dataframe ×1

pivot-table ×1