1

I am trying to obtain data for a set of months from a dataset that has thousands of rows and some columns by trying to filter data out, but the code shows an error while running

Putting in sample data-frame for the sake of the code

import pandas as pd
import matplotlib as pt
from matplotlib import dates as d
import datetime as dt
new_df =  pd.DataFrame( 
    columns = ['From Date',   'NO',          'NO2',       'NOx',    'CO',           'Ozone'],           
    data = [
        ['2018-08-30 00:00:00', 5.856666,    39.208341,   28.97,   331.280881,  19.778900],
        ['2018-08-30 01:00:00', 4.050059,    16.262145,   13.53,   454.031703,  25.075286],
        ['2018-08-30 02:00:00', 4.057806,    15.293990,   12.96,   466.502681,  24.825294],
        ['2018-08-30 03:00:00', 3.835476,    13.526193,   11.71,   446.526784,  25.033312],
        ['2018-08-30 04:00:00', 4.230690,    11.251531,   10.70,   355.638469,  25.748796],
        ['2020-08-01 05:00:00',    1,            2,        6.91,    4,             5],
['2020-03-01 06:00:00',            5,           10,        7.37,    13.2,          9],
['2020-03-01 07:00:00',            4,           13,        8.28,    4,             4],
['2020-03-01 08:00:00',            3,           9,         8.57,    3,             5],
['2020-03-01 09:00:00',            2,           4,         9.12,    4,             6]
    ]
)

new_df['From Date'] = pd.to_datetime(new_df['From Date'])
new_df['Month'] = pd.DatetimeIndex(new_df['From Date']).month
filt=(new_df['Month']>= 3) & (new_df['Month'] <= 8)
new_df.loc(filt)

Error-

'Series' objects are mutable, thus they cannot be hashed

0 Answers0