我的情况是,在对数据框应用分组之前,顺序是升序,但是在应用数据框后,命令会发生变化并在内部发生变化。
以下是代码示例: DataFrame:`
final_day_wise = daily_sales_data.loc [ : ,
['Placement#',"Placement# Name" , "Date" , "Delivered Impressions" , "Clicks" , "CTR" , "Conversion" ,
"eCPA" , "Spend" ] ]`
基于"位置#"的值的顺序;列,按升序排列。
输出,因此在应用分组时实际上是以反向或任何其他顺序更改顺序。
startline = len ( placement_sales_data ) + len ( final_adsize ) + 18
for placement , placement_df in final_day_wise.groupby ( 'Placement# Name' ):
writing_daily_data = placement_df.to_excel ( self.config.writer , sheet_name = "Standard banner({})".format (
self.config.IO_ID ) ,encoding = 'UTF-8' ,startcol = 1 ,
startrow = startline , columns = ["Placement# Name"],index = False ,
header = False , merge_cells = False)
writing_daily_data_new = placement_df.to_excel ( self.config.writer , sheet_name = "Standard banner({})".format (
self.config.IO_ID ) , startcol = 1 , startrow = startline+1 ,columns = ["Date","Delivered Impressions","Clicks","CTR",
"Conversion","eCPA","Spend"], index = False , header = True , merge_cells = False)
startline += len(placement_df) + 5
所以有任何功能或任何可以保持顺序相同的东西。
答案 0 :(得分:0)
这是你在找什么?
processed_df = df.groupby('col').agg(...).reset_index()
processed_df.sort_values(['col', 'Placement#'], ascending=True, inplace=True)