I want to transform a numpy int64 array
Zed 49
Kassadin 39
Cassiopeia 34
RekSai 33
Nidalee 30
Name: value, dtype: int64
into a list like this:
[(Zed, 49), (Kassadin, 39), (Cassiopeia, 34), (RekSai, 33), (Nidalee, 30)]
Till now I've tried:
l = l.tolist()
lT
and
[row for row in lT]
but the output looks like this:
[49, 39, 34, 33, 30]
One possible solution is list comprehenstion:
L = [(k, v) for k, v in series.items()]
Or convert values to DataFrame anf then to list ot tuples:
L = list(map(tuple, series.reset_index().values.tolist()))
Or to MultiIndex
:
L = series.to_frame('a').set_index('a', append=True).index.tolist()
print (L)
[('Zed', 49), ('Kassadin', 39), ('Cassiopeia', 34), ('RekSai', 33), ('Nidalee', 30)]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.