SoFunction
Updated on 2024-11-15

Detailed pandas delete missing data (method)

1. Create a database with missing values:

import pandas as pd
import numpy as np

df = ((5, 3), index = list('abcde'), columns = ['one', 'two', 'three'])    # Randomly generate 5 rows and 3 columns of data
[1, :-1] =     # Define specified data as missing
[1:-1, 2] = 

print('\ndf1')    # Output df1, then newline
print(df)

View data content:

2. Normally, rows are deleted with axis = 0, and columns are deleted with axis = 1, which is usually not done, as that would delete a variable.

print('\ndrop row')
print((axis = 0))

Result after deletion:

This is the whole content of this article.