I was trying to explore data using Python and this is my code :
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.read_csv('transactions-pet_store-clean.csv')
common_category_cat = df[df['Product_Line'] == 'Cat'].groupby('Product_Category')['Quantity'].sum().idxmax()
common_category_dog = df[df['Product_Line'] == 'Dog'].groupby('Product_Category')['Quantity'].sum().idxmax()
# Displaying the results
print("Common category for cats:", common_category_cat)
print("Common category for dogs:", common_category_dog)`
When trying to run the code , these errrors occured :
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-1-3ef163bcf298> in <module>
5 df = pd.read_csv('transactions-pet_store-clean.csv')
6
----> 7 common_category_cat = df[df['Product_Line'] == 'Cat'].groupby('Product_Category')['Quantity'].sum().idxmax()
8 common_category_dog = df[df['Product_Line'] == 'Dog'].groupby('Product_Category')['Quantity'].sum().idxmax()
/opt/conda/lib/python3.7/site-packages/pandas/core/series.py in idxmax(self, axis, skipna, *args, **kwargs)
2108 """
2109 skipna = nv.validate_argmax_with_skipna(skipna, args, kwargs)
-> 2110 i = nanops.nanargmax(com.values_from_object(self), skipna=skipna)
2111 if i == -1:
2112 return np.nan
/opt/conda/lib/python3.7/site-packages/pandas/core/nanops.py in _f(*args, **kwargs)
67 try:
68 with np.errstate(invalid="ignore"):
---> 69 return f(*args, **kwargs)
70 except ValueError as e:
71 # we want to transform an object array
/opt/conda/lib/python3.7/site-packages/pandas/core/nanops.py in nanargmax(values, axis, skipna, mask)
873 values, True, fill_value_typ="-inf", mask=mask
874 )
--> 875 result = values.argmax(axis)
876 result = _maybe_arg_null_out(result, axis, mask, skipna)
877 return result
ValueError: attempt to get argmax of an empty sequence`