python - How to rewrite this code to list comprehension -


i trying append string each value in df. i'd improve speed of code (big df). tried rewrite code , use list comprehension, stuck. here snippet of code:

beginning ='begin ' #word on beginning of column c=list(df.columns) #list of column in dataframe  in c:     df[i] = beginning + df[i].astype(str) 

can me, please?

just string addition dataframe.

here's example dataframe multiple columns of different types.

in [823]: df out[823]:     b          c    d 0   1 2010-03-31  1.0 1  b  2 2010-04-01  2.0 2  c  3 2010-04-02  3.0 

convert str type , add string.

in [824]: 'begin ' + df.astype(str) out[824]:                 b                 c          d 0  begin  begin 1  begin 2010-03-31  begin 1.0 1  begin b  begin 2  begin 2010-04-01  begin 2.0 2  begin c  begin 3  begin 2010-04-02  begin 3.0 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -