python - Conditional creation of a Pandas Dataframe Column -


i'm trying use np.where filter column speed , condition met assign value in column 'c'. reason i'm assigning true. seems work fine person so question i'm little stumped. appreciated.

df["c"] = np.where(df.speed > 3, 'true','false')

   speed   c   0  3.34    true   1  0.02    true   2  0.01    true   3  8.41    true   4  0.03    true   

your variables speed aren't integers, test failing. possible objects. if dataframe initialized integers, works expected.

for example, can output have here if make of datatypes of speed column strings.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

How to merge four videos on one screen with ffmpeg -

c - getting error: cannot take the address of an rvalue of type 'int' -