I have a dataframe as below
month 0 1 1 2 2 3 3 10 4 11
for example, I would like to display this data file in 2 digits, like this
month 0 01 1 02 2 03 3 10 4 11
I tried many methods but did not work. How can I get this result?
You can use str.zfill:
str.zfill
print (df['month'].astype(str).str.zfill(2)) 0 01 1 02 2 03 3 10 4 11 Name: month, dtype: object
I would choose @jezrael's answer to this, but I also like this answer
df.month.apply('{:02d}'.format) 0 01 1 02 2 03 3 10 4 11 Name: month, dtype: object
Source: https://habr.com/ru/post/1657468/More articles:parsing csv data in javascript not working in chrome - javascriptIs Vaadin Elements intended for use with the Vaadin Framework? - javaHow to use MS-IoT Lightning to install / receive PWM using raspberry Pi2? - c #\ x does not work inside a replacement - regexReorder pandas frame rows based on list and keep order - numpyКак установитьNestedScrollingEnabled в устройствах с предварительным леоптипом. - androidHow Java 8 time api selects an offset during a DST change period - javaTYPO3 Extbase: How to get an object associated with an object without raw sql query? - typo3How to remove unicode from a string? - regexGet default initialized (NOT value / zero-initialized) POD as rvalue - c ++All Articles