удали все строчки из датафрэйма где содержится nan in python

To delete all rows from a dataframe that contain NaN values in Python using Pandas, you can use the dropna() function. Here is an example:

main.py
import pandas as pd

# Creating a sample dataframe
data = {'Column1': [1, 2, 3, float('nan'), 5],
        'Column2': [float('nan'), 7, 8, 9, 10],
        'Column3': [11, 12, 13, 14, float('nan')]}

df = pd.DataFrame(data)

# Removing rows with NaN values
df.dropna(inplace=True)
279 chars
12 lines

The dropna() function with the inplace=True parameter will remove all rows with any NaN values from the dataframe.

related categories

gistlibby LogSnag