Skip to content Skip to sidebar Skip to footer

Detecting Specific Character In Dataframe

I have a dataframe using pandas (/python) that looks like this: in the wow column, it is defined that it has the value of 0 and 1, I wonder how to process that into another datafr

Solution 1:

You can create boolean masks for the conditions of 0 adjacent to 1 and filter by using df.loc, as follows:

m1 = (df['wow'] == 0.0) & (df['wow'].shift(-1) == 1.0)
m2 = (df['wow'] == 0.0) & (df['wow'].shift(1) == 1.0)
df.loc[m1 | m2]

Output:

    time_s  wow    lat_deg    lon_deg
3      6.0  0.0  35.042628 -89.978249
5     10.0  0.0  35.042628 -89.978249
7     14.0  0.0  35.042628 -89.978249
10    20.0  0.0  35.042628 -89.978249


Post a Comment for "Detecting Specific Character In Dataframe"