How to pad leading zeros to the Time column?











up vote
0
down vote

favorite












Using 'df_dropped', a data frame, which has a column 'Time'.



df_dropped['Time'] = df_dropped['Time'].apply(lambda x:'{:0>4}'.format(x))


I don't understand what the '{:0>4}'.format(x)' does.
Please explain the construction of this line '{:0>4}'.format(x)'










share|improve this question




















  • 2




    What you are looking for might be answered here: stackoverflow.com/questions/4008546/…
    – DMarczak
    Nov 13 at 5:22












  • Possible duplicate of How to pad with n characters in Python
    – user3287355
    Nov 13 at 5:31










  • Explained here:- datacamp-global.slack.com/archives/C654VRAJ2/…
    – Manideep Pullalachervu
    2 days ago

















up vote
0
down vote

favorite












Using 'df_dropped', a data frame, which has a column 'Time'.



df_dropped['Time'] = df_dropped['Time'].apply(lambda x:'{:0>4}'.format(x))


I don't understand what the '{:0>4}'.format(x)' does.
Please explain the construction of this line '{:0>4}'.format(x)'










share|improve this question




















  • 2




    What you are looking for might be answered here: stackoverflow.com/questions/4008546/…
    – DMarczak
    Nov 13 at 5:22












  • Possible duplicate of How to pad with n characters in Python
    – user3287355
    Nov 13 at 5:31










  • Explained here:- datacamp-global.slack.com/archives/C654VRAJ2/…
    – Manideep Pullalachervu
    2 days ago















up vote
0
down vote

favorite









up vote
0
down vote

favorite











Using 'df_dropped', a data frame, which has a column 'Time'.



df_dropped['Time'] = df_dropped['Time'].apply(lambda x:'{:0>4}'.format(x))


I don't understand what the '{:0>4}'.format(x)' does.
Please explain the construction of this line '{:0>4}'.format(x)'










share|improve this question















Using 'df_dropped', a data frame, which has a column 'Time'.



df_dropped['Time'] = df_dropped['Time'].apply(lambda x:'{:0>4}'.format(x))


I don't understand what the '{:0>4}'.format(x)' does.
Please explain the construction of this line '{:0>4}'.format(x)'







python pandas dataframe data-science






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 at 13:12

























asked Nov 13 at 5:15









Manideep Pullalachervu

11




11








  • 2




    What you are looking for might be answered here: stackoverflow.com/questions/4008546/…
    – DMarczak
    Nov 13 at 5:22












  • Possible duplicate of How to pad with n characters in Python
    – user3287355
    Nov 13 at 5:31










  • Explained here:- datacamp-global.slack.com/archives/C654VRAJ2/…
    – Manideep Pullalachervu
    2 days ago
















  • 2




    What you are looking for might be answered here: stackoverflow.com/questions/4008546/…
    – DMarczak
    Nov 13 at 5:22












  • Possible duplicate of How to pad with n characters in Python
    – user3287355
    Nov 13 at 5:31










  • Explained here:- datacamp-global.slack.com/archives/C654VRAJ2/…
    – Manideep Pullalachervu
    2 days ago










2




2




What you are looking for might be answered here: stackoverflow.com/questions/4008546/…
– DMarczak
Nov 13 at 5:22






What you are looking for might be answered here: stackoverflow.com/questions/4008546/…
– DMarczak
Nov 13 at 5:22














Possible duplicate of How to pad with n characters in Python
– user3287355
Nov 13 at 5:31




Possible duplicate of How to pad with n characters in Python
– user3287355
Nov 13 at 5:31












Explained here:- datacamp-global.slack.com/archives/C654VRAJ2/…
– Manideep Pullalachervu
2 days ago






Explained here:- datacamp-global.slack.com/archives/C654VRAJ2/…
– Manideep Pullalachervu
2 days ago














1 Answer
1






active

oldest

votes

















up vote
0
down vote













It adds 0 character to each elements of data-frame until it reach 4 character. If the element is more than 4 character will do nothing.
you can see below example:



import pandas as pd

df = pd.DataFrame(data=[23, "fsda", 289801, 87], columns=['Time'], index=[0, 1, 2, 3])
df['Time'] = df['Time'].apply(lambda x: '{:0>6}'.format(x))





share|improve this answer





















  • '{:0>6}'.format(x) can you explain this bit of code
    – Manideep Pullalachervu
    Nov 14 at 4:44











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274249%2fhow-to-pad-leading-zeros-to-the-time-column%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













It adds 0 character to each elements of data-frame until it reach 4 character. If the element is more than 4 character will do nothing.
you can see below example:



import pandas as pd

df = pd.DataFrame(data=[23, "fsda", 289801, 87], columns=['Time'], index=[0, 1, 2, 3])
df['Time'] = df['Time'].apply(lambda x: '{:0>6}'.format(x))





share|improve this answer





















  • '{:0>6}'.format(x) can you explain this bit of code
    – Manideep Pullalachervu
    Nov 14 at 4:44















up vote
0
down vote













It adds 0 character to each elements of data-frame until it reach 4 character. If the element is more than 4 character will do nothing.
you can see below example:



import pandas as pd

df = pd.DataFrame(data=[23, "fsda", 289801, 87], columns=['Time'], index=[0, 1, 2, 3])
df['Time'] = df['Time'].apply(lambda x: '{:0>6}'.format(x))





share|improve this answer





















  • '{:0>6}'.format(x) can you explain this bit of code
    – Manideep Pullalachervu
    Nov 14 at 4:44













up vote
0
down vote










up vote
0
down vote









It adds 0 character to each elements of data-frame until it reach 4 character. If the element is more than 4 character will do nothing.
you can see below example:



import pandas as pd

df = pd.DataFrame(data=[23, "fsda", 289801, 87], columns=['Time'], index=[0, 1, 2, 3])
df['Time'] = df['Time'].apply(lambda x: '{:0>6}'.format(x))





share|improve this answer












It adds 0 character to each elements of data-frame until it reach 4 character. If the element is more than 4 character will do nothing.
you can see below example:



import pandas as pd

df = pd.DataFrame(data=[23, "fsda", 289801, 87], columns=['Time'], index=[0, 1, 2, 3])
df['Time'] = df['Time'].apply(lambda x: '{:0>6}'.format(x))






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 at 14:10









saeed heidari

1644




1644












  • '{:0>6}'.format(x) can you explain this bit of code
    – Manideep Pullalachervu
    Nov 14 at 4:44


















  • '{:0>6}'.format(x) can you explain this bit of code
    – Manideep Pullalachervu
    Nov 14 at 4:44
















'{:0>6}'.format(x) can you explain this bit of code
– Manideep Pullalachervu
Nov 14 at 4:44




'{:0>6}'.format(x) can you explain this bit of code
– Manideep Pullalachervu
Nov 14 at 4:44


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53274249%2fhow-to-pad-leading-zeros-to-the-time-column%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?