Drop Infinite Values from pandas DataFrame in Python (Examples) | Replace inf by NaN | NumPy Library

Pubblicato il: 18 novembre 2022
sul canale di: Statistics Globe
561
13

How to remove infinite values from a pandas DataFrame in the Python programming language. More details: https://statisticsglobe.com/drop-inf-...
Python code of this video:

import pandas as pd # Load pandas library

import numpy as np # Import NumPy library in Python

data = pd.DataFrame({'x1':range(1, 6), # Create example DataFrame
'x2':[1, np.inf, 1, 1, 1],
'x3':[5, np.inf, 6, 7, np.inf]})
print(data) # Print example DataFrame

data_new1 = data.copy() # Create duplicate of data
data_new1.replace([np.inf, - np.inf], np.nan, inplace = True) # Exchange inf by NaN
print(data_new1) # Print data with NaN

data_new2 = data_new1.dropna() # Delete rows with NaN
print(data_new2) # Print final data set

Follow me on Social Media:
Facebook – Statistics Globe Page:   / statisticsglobecom  
Facebook – R Programming Group for Discussions & Questions:   / statisticsglobe  
Facebook – Python Programming Group for Discussions & Questions:   / statisticsglobepython  
LinkedIn – Statistics Globe Page:   / statisticsglobe  
LinkedIn – R Programming Group for Discussions & Questions:   / 12555223  
LinkedIn – Python Programming Group for Discussions & Questions:   / 12673534  
Twitter:   / joachimschork  

Music by bensound.com


In questa pagina del sito puoi guardare il video online Drop Infinite Values from pandas DataFrame in Python (Examples) | Replace inf by NaN | NumPy Library della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Statistics Globe 18 novembre 2022, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 561 volte e gli è piaciuto 13 spettatori. Buona visione!