So, in general, numpy.ndarray objects have limited support for string operations. Notably, string slicing seems to be absent. If you look at similar questions, you can hack a slice from the front at least using a view (with a small N for the UN type). However, since your array is a structured dtype, it doesn't like creating views.
In this particular case, though, you can use the np.char.startswith function.
Some example data (please always provide this in the future, you are coming here asking for help, don't make people work to make your own question easy to answer, it's actually part of the rules, but it is also just common courtesy):
(py39) Juans-MBP:workspace juan$ cat resale.csv
2017-01,foo,4560.0
2019-01,bar,3432.34
2017-01,baz,34199.5
2019-01,baz,3232.34
2017-01,bar,932.34
Ok, so using that above:
In [1]: import numpy as np
In [2]: resale = "resale.csv"
In [3]: data = np.loadtxt(resale,dtype=[('month','U50'),('flat_type','U50'),
...: ('resale_price','f8')],delimiter=',')
In [4]: data
Out[4]:
array([('2017-01', 'foo', 4560. ), ('2019-01', 'bar', 3432.34),
('2017-01', 'baz', 34199.5 ), ('2019-01', 'baz', 3232.34),
('2017-01', 'bar', 932.34)],
dtype=[('month', '<U50'), ('flat_type', '<U50'), ('resale_price', '<f8')])
In [5]: np.char.startswith(data['month'], "2019")
Out[5]: array([False, True, False, True, False])
In [6]: data[np.char.startswith(data['month'], "2019")]
Out[6]:
array([('2019-01', 'bar', 3432.34), ('2019-01', 'baz', 3232.34)],
dtype=[('month', '<U50'), ('flat_type', '<U50'), ('resale_price', '<f8')])
Alternatively, though, in this case you are working with dates, which is a supported type in numpy, so you can use the following dtype: 'datetime64[D]' which will be a datetime64 but parsed by filling in the days for you:
In [14]: data = np.loadtxt(resale,dtype=[('month','datetime64[D]'),('flat_type','U50'),
...: ('resale_price','f8')],delimiter=',')
In [8]: data
Out[8]:
array([('2017-01-01', 'foo', 4560. ), ('2019-01-01', 'bar', 3432.34),
('2017-01-01', 'baz', 34199.5 ), ('2019-01-01', 'baz', 3232.34),
('2017-01-01', 'bar', 932.34)],
dtype=[('month', '<M8[D]'), ('flat_type', '<U50'), ('resale_price', '<f8')])
Then you can use something like:
In [9]: data['month'] >= np.datetime64("2019")
Out[9]: array([False, True, False, True, False])
dataresale[dataresale['month'][:4]=="2021"]?numpyhere, working with strings is going to be unwieldy. In any case, you really should provide example data.