Stack Overflow Asked by Lostsoul on December 16, 2021
I have a numpy array –
['L', 'London', 'M', 'Moscow', 'NYC', 'Paris', 'nan']
I want ‘nan’ to be first, like so:
['nan', 'L', 'London', 'M', 'Moscow', 'NYC', 'Paris']
How can I do that?
If you want to use numpy
, you can use numpy.roll
:
a = np.array(['L', 'London', 'M', 'Moscow', 'NYC', 'Paris', 'nan'])
a = np.roll(a, 1)
print(a)
Prints:
['nan' 'L' 'London' 'M' 'Moscow' 'NYC' 'Paris']
Answered by Andrej Kesely on December 16, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP