How to append a 1 to the end of each single digit element within an array, list, or dataframe in Python Pandas? -


i found difficult array, whatever output method fine me. want take column dataframe has single digits numbers , double digits numbers.
items integers, can converted str or bool, whatever necessary task.

i want add 1 end of single digits example, if first digit 2, want return 21.

lastly, once these operations complete, need split digits in half , create 2 columns. example

col['a'] = [3, 22, 23, 2, 1]  

so output should like:

col['a'] = [31, 22, 23, 21, 11]  

then,

col['b'] = col['a'][0:]  [3,2,2,2,1]  

and

col['c'] = col['a'][:1]  [1,2,3,1,1].       

>>> df     0   3 1  22 2  23 3   2 4   1  df['aa'] = df.apply(lambda row: row['a']*10+1 if 0<=row['a']<=9 else row['a'], axis=1)  >>> df      aa 0   3  31 1  22  22 2  23  23 3   2  21 4   1  11  df['b'] = df.apply(lambda row: divmod(row['aa'], 10)[0], axis=1) df['c'] = df.apply(lambda row: divmod(row['aa'], 10)[1], axis=1)  >>> df      aa  b  c 0   3  31  3  1 1  22  22  2  2 2  23  23  2  3 3   2  21  2  1 4   1  11  1  1 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -