Issue
i have not seen such question, so if you happen to know the answer or have seen the same question, please let me know
i have a dataframe in pandas with 4 columns and 5k rows, one of the columns is "price" and i need to do some manipulations with it. but the data was parsed from web-page and it is not clean, so i cannot convert this column to integer type after getting rid of dollar sign and comas. i found out that it also contains data in the format 3500/mo
. so i need to filter cells with /mo
and decide whether i can drop them, basing on how many of those i have and what is the price.
now, i have managed to count those cells using
df["price"].str.contains("/").sum()
but when i want to see those cells, i cannot do that, because when i create another variable to extract slash-containing cells and use "contains" or smth, i get the series with true/false values - showing me the condition of whether the cell does or does not contain that slash, while i actually need to see cells themselves. any ideas?
Solution
You need to use the boolean mask returned by df["price"].str.contains("/")
as index to get the respective rows, i.e., df[df["price"].str.contains("/")]
(cf. the pandas docs on indexing).
Answered By - fsimonjetz
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.