0

I have a DataFrame sy_wx as below:

enter image description here

And I wish to drop any row with minutes not equal to zero to look like.

enter image description here

Using

sy_wx = sy_wx[sy_wx['time_utc'].minute == 0]

gives AttributeError: 'Series' object has no attribute 'minute' error

but

In [50]: sy_wx['time_utc'][1].minute
Out[50]: 30

Where am I going wrong?

Tim
  • 63
  • 7

2 Answers2

2

first, make sure your datatype for time_utc column is DateTime. You can convert object(str) to DateTime using this code:

sy_wx['time_utc'] = pd.to_datetime(sy_wx['time_utc'])

then use this code to filter your data:

sy_wx = sy_wx[sy_wx['time_utc'].dt.minute == 0]

you are missing dt before minute

Hamid
  • 612
  • 1
  • 8
  • 20
1

We need use dt to get the minute

sy_wx = sy_wx[sy_wx['time_utc'].dt.minute == 0].copy() # also add copy at the end , for set copy error
BENY
  • 317,841
  • 20
  • 164
  • 234
  • Thanks @YOBEN_S. Any chance you could elaborate on the .copy() at the end? – Tim May 12 '20 at 01:03
  • 1
    https://stackoverflow.com/questions/20625582/how-to-deal-with-settingwithcopywarning-in-pandas @Tim – BENY May 12 '20 at 01:21