-1

Trying to find rows of a column which end in .99 cents

len(df_official.loc[(df_official.price_duration_days >= 7) & (df_official.shop.isin(official_stores)) & (df_official['Days From Release'] <= 3) & (str(df_official.y)[-3:] == '.99')])

(str(df_official.y)[-3:] == '.99') is the piece not functioning.

y is a dataframe column of float.64 dtype.

I'm trying to have this conditional in the .loc function above, but the issue is both the str() and the [-3:] for reasons I see.

I know an alternative approach by creating a temporary column, but what I'm wondering is: Is there a way to approach this kind of manipulation within .loc[] or .where()?

len(df_official.loc[str(df_official['y'][-3:]) == '.99'])

KeyError: 'False: boolean label can not be used without a boolean index'

len(df_official.loc[[str(df_official['y'][-3:]) == .99]])

IndexError: Boolean index has wrong length: 1 instead of 555

Prototype
  • 1
  • 1

1 Answers1

0

str() is the wrong approach. .astype(str).str.endswith() solves it.

len(df_official.loc[df_official['y'].astype(str).str.endswith('.99')])

Prototype
  • 1
  • 1