python - Most efficient way to convert pandas series of integers to strings? -


.type (str) is the most efficient way of changing a series of ints for a series of stars? It seems very slow, so I wanted to ask

I tried some things and numpy Using fast:

  setup = "" import panda, numpy s = pandas.Series (numpy.random.randint (1,10, (100)) "" "Gt; & Gt; & Gt; Timeit.timeit ('s.astype (str)', setup = setup, number = 10000) 3.33058500289917 & gt; & Gt; & Gt; Timeit.timeit ('s.apply (str)', setup = setup, number = 10000) 3.572000026702881 & gt; & Gt; & Gt; Timeit.timeit ('s.apply (lambda x: str (x)), setup = setup, number = 10000) 3.821247100830078 & gt; & Gt; & Gt; Timeit.timeit ('s.values.astype (numpy.str)', setup = setup, number = 10000) 0.08432412147521973  

As you can see, with numpy Accesing the array and astype calls are faster than 40x faster in the next fastest way.


Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -