PythonException: 'TypeError: unsupported operand tipo(s) per divmod(): 'NoneType' e 'int"

0

Domanda

Ho questa funzione che converte secondi per gg:hh:mm:ss (stringa) - tuttavia, quando c'è un null istanza dalla colonna di input, ho visualizzato l'errore PythonException: 'TypeError: unsupported operand tipo(s) per divmod(): 'NoneType' e 'int".

c'è una correzione che può essere messo all'interno della funzione, di seguito -

  def to_hms(s):
 m, s = divmod(s, 60)
 h, m = divmod(m, 60)
 d, h = divmod(h, 24)
 return '{}:{:0>2}:{:0>2}:{:0>2}'.format(d, h, m, s)
function pyspark python
2021-11-23 22:05:07
1

Migliore risposta

0

Forse questo ti può aiutare:

def to_hms(s):
    if s:
        m, s = divmod(s, 60)
        h, m = divmod(m, 60)
        d, h = divmod(h, 24)
        return '{}:{:0>2}:{:0>2}:{:0>2}'.format(d, h, m, s)
    return '0:00:00:00'

Questo restituirà valore vuoto, se non si trova il valore per s.

2021-11-23 22:22:43

Grande, ha funzionato esattamente come necessari; grazie!
JSingh1996

Sei il benvenuto!
Sakshi Sharma

In altre lingue

Questa pagina è in altre lingue

Русский
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................