I have a dataframe with several OrderId, Date of sale, product taht was sale and so on. I am currently trying to calculate the month in which were sold less Motorcycles.
This is the code I wrote, trying with group by to calculate the total amount sold en each month:
Motorcycles =sales_data.loc[sales_data['PRODUCTLINE'] == 'Motorcycles']
Motorcycles['ORDERDATE'] = pd.to_datetime(Motorcycles['ORDERDATE'])
Motorcycles.groupby(pd.Grouper(freq='M'))
Warning shown is: :10: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy Motorcycles['ORDERDATE'] = pd.to_datetime(Motorcycles['ORDERDATE'])
Error shown is: ERROR: TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'Int64Index'
I tried also with and this neither works.
Motorcycles.set_index('ORDERDATE').resample('1M').sum()
df.head(10) results: