Невозможно суммировать общее количество часов работы в лямбда-функции группы панд - PullRequest
0 голосов
/ 01 октября 2019

Ниже приведен код

import pandas as pd  
  school_diesel =pd.read_excel(r'********\school Generator   Diesel Log 23-09-2019 17_59_05.xlsx',heading=[1,2])  
  school_running = pd.read_excel(r'*********\school Generator Daily Log 23-09-2019 18_09_41.xlsx',0)   
school_diesel.columns = school_diesel.iloc[0] # replace headings with next row values
school_running.columns = school_running.iloc[0] # replace headings with next row values  
school_running.columns  
school_diesel.columns  
school_diesel.drop(school_diesel.head(1).index, inplace=True) #drop first row of the table- as this repeated heading  
school_running.drop(school_running.head(1).index, inplace=True) #drop first row of the table- as this repeated heading  
school_running['Time'] = school_running['Running Hours'].astype(str).map(lambda x: x[-1:] + x[:x.find("-")])  

school_running[school_running['Generator On Date']>'2019-08-01 00:00:00'].groupby(['Zone', 'Branch', 'Building Code', ' Branch Type ','AC or Non AC', ' Student Strength ', 'Company Name', 'Gen SNo','Capacity KVA', 'Fuel Capacity']).agg({'Time': lambda x:(pd.to_timedelta(x).sum().total_seconds)//(1290000),'Diesel Consumed':np.sum})

* Типы данных *

school_running.info()

<class 'pandas.core.frame.DataFrame'>  
RangeIndex: 12467 entries, 0 to 12466  
Data columns (total 28 columns):  
Sno                       12467   non-null object  
City                      12466   non-null object  
Zone                      12466   non-null object  
Branch                    12466   non-null object  
Building Code             12382   non-null float64  
 Branch Type              12304   non-null object  
AC or Non AC              11405   non-null object  
 Student Strength         12467   non-null int64  
Company Name              12381   non-null object  
Gen SNo                   12467   non-null object  
Capacity KVA              12381   non-null float64  
Fuel Capacity             12467   non-null int64  
Last Diesel Purchase      12467   non-null datetime64[ns]  
Purchase Qty              12467   non-null float64  
Amount                    12467   non-null float64  
Last Fuel Filled          12467   non-null datetime64[ns]  
Filling Qty               12467   non-null float64  
Diesel Opening Qty        12467   non-null float64  
Generator On Date         12467   non-null datetime64[ns]  
Generator Off Date        12467   non-null datetime64[ns]  
Running Hours             12467   non-null object  
Consumed Units            12467   non-null float64  
Diesel Consumed           12467   non-null float64  
Diesel Balance Qty        12467   non-null float64  
Remarks                   6270    non-null object  
Unnamed: 25               1       non-null float64  
Hours                     12467   non-null float64  
Time                      12467   non-null object  
dtypes: datetime64[ns](4), float64(11), int64(2), object(11)  

я хочу, чтобы выходная информация была равна сумме общих часов и общего потребленного дизельного топлива

Ошибка вывода:

<ipython-input-66-21d53e6eaa72> in <lambda>(x)
----> 1 school_running[school_running['Generator On Date']>'2019-08-01 00:00:00'].groupby(['Zone', 'Branch', 'Building Code', ' Branch Type ','AC or Non AC', ' Student Strength ', 'Company Name', 'Gen SNo','Capacity KVA', 'Fuel Capacity']).agg({'Time': lambda x:(pd.to_timedelta(x).sum().total_seconds)//(1290000),'Diesel Consumed':np.sum})

TypeError: unsupported operand type(s) for //: 'builtin_function_or_method' and 'int'

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...