Issue
df2 = df[["Time","A"]]
I have a dataframe (df2) and I need to make the "Time" line contain only values (>=0)
I tried
df2['Time'] = df2[['Time']].astype(float)
and i gave a problem
ValueError: could not convert string to float: '(с)'
i think because of first line. how can i change this?
In next operation i want to do
df_positive = df2[df2[('Time')] > 0]
Solution
You have 2 options
clean up your data (make sure you don't have any strings in float columns) - either before reading, or after reading
ask pandas to convert the (dirty) column to numeric, and tell pandas to coerce errors (i.e., fill with
np.NaN
, if that's what you prefer):pd.to_numeric(df2['Time'], errors='coerce')
Answered By - KingOtto
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.