I'm quite new to python. I am trying to iterate through list columns using an 'if' statement with 2 conditions. The return statement I keep getting is "The truth value of a Series is ambiguous (when iterating through a series using if statement"
Below is my code (the data frame consists of app data from Google Play Store)
import pandas as pd
df = pd.read_csv("googleplaystore.csv")
df.tail()
df["Rating"].fillna(value = '0.0', inplace= True)
medical_app_ratings = []
for row in df[1:]:
rating = df.Rating
genre = df.Genres
if genre == "Medical":
medical_app_ratings.append(rating)
ValueError Traceback (most recent call last)
<ipython-input-154-51c7806c01da> in <module>
5 rating = df.Rating
6 genre = df.Genres
----> 7 if genre == "Medical":
8 medical_app_ratings.append(rating).bool()
9
~\anaconda3\lib\site-packages\pandas\core\generic.py in __nonzero__(self)
1477 def __nonzero__(self):
1478 raise ValueError(
-> 1479 f"The truth value of a {type(self).__name__} is ambiguous. "
1480 "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
1481 )
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
If anyone could please tell me what I am doing wrong I would truly appreciate it.
Aucun commentaire:
Enregistrer un commentaire