pandas masking

I'm Cape·2023년 6월 24일
0
test = {
	'A': [0.1, 33, -5],
    'B': [1, -7, np.nan]
}

df = pd.DataFrame(test)

df > 0

df[df > 0]

df.mask(df > 0)

The mask method is an application of the if-then idiom. For each element in the calling DataFrame, if cond is False the element is used; otherwise the corresponding element from the DataFrame other is used.

df.mask(df > 0, other=100)

df.where(df > 0)


The where method is an application of the if-then idiom. For each element in the calling DataFrame, if cond is True the element is used; otherwise the corresponding element from the DataFrame other is used.

df.where(df > 0)

profile
Impact

0개의 댓글