column with a fixed number of numbers Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!How do I check if a string is a number (float)?How do I get the number of elements in a list in Python?Selecting multiple columns in a pandas dataframeRenaming columns in pandasAdding new column to existing DataFrame in Python pandasHow to change the order of DataFrame columns?Delete column from pandas DataFrame by column nameSelect rows from a DataFrame based on values in a column in pandasGet list from pandas DataFrame column headersCounting unique values in columns - pandas Python

Do I really need to have a message in a novel to appeal to readers?

How to write capital alpha?

What order were files/directories output in dir?

Is it possible for SQL statements to execute concurrently within a single session in SQL Server?

Google .dev domain strangely redirects to https

AppleTVs create a chatty alternate WiFi network

What would you call this weird metallic apparatus that allows you to lift people?

What does this say in Elvish?

What does it mean that physics no longer uses mechanical models to describe phenomena?

If the probability of a dog barking one or more times in a given hour is 84%, then what is the probability of a dog barking in 30 minutes?

How could we fake a moon landing now?

How does light 'choose' between wave and particle behaviour?

One-one communication

Why can't I install Tomboy in Ubuntu Mate 19.04?

What's the difference between the capability remove_users and delete_users?

macOS: Name for app shortcut screen found by pinching with thumb and three fingers

Misunderstanding of Sylow theory

What does 丫 mean? 丫是什么意思?

Central Vacuuming: Is it worth it, and how does it compare to normal vacuuming?

Why is it faster to reheat something than it is to cook it?

Why are vacuum tubes still used in amateur radios?

How can I set the aperture on my DSLR when it's attached to a telescope instead of a lens?

An adverb for when you're not exaggerating

Do wooden building fires get hotter than 600°C?



column with a fixed number of numbers



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!How do I check if a string is a number (float)?How do I get the number of elements in a list in Python?Selecting multiple columns in a pandas dataframeRenaming columns in pandasAdding new column to existing DataFrame in Python pandasHow to change the order of DataFrame columns?Delete column from pandas DataFrame by column nameSelect rows from a DataFrame based on values in a column in pandasGet list from pandas DataFrame column headersCounting unique values in columns - pandas Python



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm trying to automate an excel work using pandas.



I have a given database with a column 'reference', this column should have 2 numbers (example: 25, 53, 45...).



I need to have all the rows in the column with two numbers but references like 1, 2, 3, 4 until 9 are only 1 number.



Is there a function I can add in order to transform the whole rows of this column to two numbers reference?



I have already tried the if-statement but it didn't give any result.



sorry for my English, I hope I made myself understood :)



import pandas as pd



df = pd.read_excel('file.xlsx')



reference# #column 2# #column 3



1 Yellow 7474
10 brown 8220
43 white 29374
45 black 993
2 brown 9220
5 brown 2929
39 black 3683



df.set_index('reference', inplace=True)



.....



My output has to be like this :



reference# #column 2# #column 3



01 Yellow 7474
10 brown 8220
43 white 29374
45 black 993
02 brown 9220
05 brown 2929
39 black 3683










share|improve this question
























  • Welcome to StackOverflow. Unfortunately its not very clear what you are asking. As you are using Pandas, I assume your data is in CSV format. Could you share an example section of your data? It may also help to share an example of the output you would like to achieve.

    – 4Oh4
    Mar 8 at 22:48

















0















I'm trying to automate an excel work using pandas.



I have a given database with a column 'reference', this column should have 2 numbers (example: 25, 53, 45...).



I need to have all the rows in the column with two numbers but references like 1, 2, 3, 4 until 9 are only 1 number.



Is there a function I can add in order to transform the whole rows of this column to two numbers reference?



I have already tried the if-statement but it didn't give any result.



sorry for my English, I hope I made myself understood :)



import pandas as pd



df = pd.read_excel('file.xlsx')



reference# #column 2# #column 3



1 Yellow 7474
10 brown 8220
43 white 29374
45 black 993
2 brown 9220
5 brown 2929
39 black 3683



df.set_index('reference', inplace=True)



.....



My output has to be like this :



reference# #column 2# #column 3



01 Yellow 7474
10 brown 8220
43 white 29374
45 black 993
02 brown 9220
05 brown 2929
39 black 3683










share|improve this question
























  • Welcome to StackOverflow. Unfortunately its not very clear what you are asking. As you are using Pandas, I assume your data is in CSV format. Could you share an example section of your data? It may also help to share an example of the output you would like to achieve.

    – 4Oh4
    Mar 8 at 22:48













0












0








0








I'm trying to automate an excel work using pandas.



I have a given database with a column 'reference', this column should have 2 numbers (example: 25, 53, 45...).



I need to have all the rows in the column with two numbers but references like 1, 2, 3, 4 until 9 are only 1 number.



Is there a function I can add in order to transform the whole rows of this column to two numbers reference?



I have already tried the if-statement but it didn't give any result.



sorry for my English, I hope I made myself understood :)



import pandas as pd



df = pd.read_excel('file.xlsx')



reference# #column 2# #column 3



1 Yellow 7474
10 brown 8220
43 white 29374
45 black 993
2 brown 9220
5 brown 2929
39 black 3683



df.set_index('reference', inplace=True)



.....



My output has to be like this :



reference# #column 2# #column 3



01 Yellow 7474
10 brown 8220
43 white 29374
45 black 993
02 brown 9220
05 brown 2929
39 black 3683










share|improve this question
















I'm trying to automate an excel work using pandas.



I have a given database with a column 'reference', this column should have 2 numbers (example: 25, 53, 45...).



I need to have all the rows in the column with two numbers but references like 1, 2, 3, 4 until 9 are only 1 number.



Is there a function I can add in order to transform the whole rows of this column to two numbers reference?



I have already tried the if-statement but it didn't give any result.



sorry for my English, I hope I made myself understood :)



import pandas as pd



df = pd.read_excel('file.xlsx')



reference# #column 2# #column 3



1 Yellow 7474
10 brown 8220
43 white 29374
45 black 993
2 brown 9220
5 brown 2929
39 black 3683



df.set_index('reference', inplace=True)



.....



My output has to be like this :



reference# #column 2# #column 3



01 Yellow 7474
10 brown 8220
43 white 29374
45 black 993
02 brown 9220
05 brown 2929
39 black 3683







python excel pandas character minimum






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 23:25







ZAKARIA

















asked Mar 8 at 22:11









ZAKARIAZAKARIA

32




32












  • Welcome to StackOverflow. Unfortunately its not very clear what you are asking. As you are using Pandas, I assume your data is in CSV format. Could you share an example section of your data? It may also help to share an example of the output you would like to achieve.

    – 4Oh4
    Mar 8 at 22:48

















  • Welcome to StackOverflow. Unfortunately its not very clear what you are asking. As you are using Pandas, I assume your data is in CSV format. Could you share an example section of your data? It may also help to share an example of the output you would like to achieve.

    – 4Oh4
    Mar 8 at 22:48
















Welcome to StackOverflow. Unfortunately its not very clear what you are asking. As you are using Pandas, I assume your data is in CSV format. Could you share an example section of your data? It may also help to share an example of the output you would like to achieve.

– 4Oh4
Mar 8 at 22:48





Welcome to StackOverflow. Unfortunately its not very clear what you are asking. As you are using Pandas, I assume your data is in CSV format. Could you share an example section of your data? It may also help to share an example of the output you would like to achieve.

– 4Oh4
Mar 8 at 22:48












1 Answer
1






active

oldest

votes


















0














Is it possible for you to post a data sample of what you have and what you are looking for?



To read in your excel document use:



df = pd.read_excel('excel_doc.xlsx')


In general, if you have a 'reference' column in pandas we would call this the 'index' column.



You can set the index by going:



df.set_index('reference_column',inplace=True)


If you are trying to add a zero in front of the numbers (less than 9) you need to turn it into a text string. You can then use zfill to 'fill' in the 0 for the numbers less than 2 digits.



df['column_of_numbers'].str.zfill(2)


Good luck!






share|improve this answer























  • Do I need to turn it to a text string in the excel file ? or using python ?

    – ZAKARIA
    Mar 8 at 23:01











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',
autoActivateHeartbeat: false,
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%2f55071712%2fcolumn-with-a-fixed-number-of-numbers%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









0














Is it possible for you to post a data sample of what you have and what you are looking for?



To read in your excel document use:



df = pd.read_excel('excel_doc.xlsx')


In general, if you have a 'reference' column in pandas we would call this the 'index' column.



You can set the index by going:



df.set_index('reference_column',inplace=True)


If you are trying to add a zero in front of the numbers (less than 9) you need to turn it into a text string. You can then use zfill to 'fill' in the 0 for the numbers less than 2 digits.



df['column_of_numbers'].str.zfill(2)


Good luck!






share|improve this answer























  • Do I need to turn it to a text string in the excel file ? or using python ?

    – ZAKARIA
    Mar 8 at 23:01















0














Is it possible for you to post a data sample of what you have and what you are looking for?



To read in your excel document use:



df = pd.read_excel('excel_doc.xlsx')


In general, if you have a 'reference' column in pandas we would call this the 'index' column.



You can set the index by going:



df.set_index('reference_column',inplace=True)


If you are trying to add a zero in front of the numbers (less than 9) you need to turn it into a text string. You can then use zfill to 'fill' in the 0 for the numbers less than 2 digits.



df['column_of_numbers'].str.zfill(2)


Good luck!






share|improve this answer























  • Do I need to turn it to a text string in the excel file ? or using python ?

    – ZAKARIA
    Mar 8 at 23:01













0












0








0







Is it possible for you to post a data sample of what you have and what you are looking for?



To read in your excel document use:



df = pd.read_excel('excel_doc.xlsx')


In general, if you have a 'reference' column in pandas we would call this the 'index' column.



You can set the index by going:



df.set_index('reference_column',inplace=True)


If you are trying to add a zero in front of the numbers (less than 9) you need to turn it into a text string. You can then use zfill to 'fill' in the 0 for the numbers less than 2 digits.



df['column_of_numbers'].str.zfill(2)


Good luck!






share|improve this answer













Is it possible for you to post a data sample of what you have and what you are looking for?



To read in your excel document use:



df = pd.read_excel('excel_doc.xlsx')


In general, if you have a 'reference' column in pandas we would call this the 'index' column.



You can set the index by going:



df.set_index('reference_column',inplace=True)


If you are trying to add a zero in front of the numbers (less than 9) you need to turn it into a text string. You can then use zfill to 'fill' in the 0 for the numbers less than 2 digits.



df['column_of_numbers'].str.zfill(2)


Good luck!







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 8 at 22:24









mikemike

7726




7726












  • Do I need to turn it to a text string in the excel file ? or using python ?

    – ZAKARIA
    Mar 8 at 23:01

















  • Do I need to turn it to a text string in the excel file ? or using python ?

    – ZAKARIA
    Mar 8 at 23:01
















Do I need to turn it to a text string in the excel file ? or using python ?

– ZAKARIA
Mar 8 at 23:01





Do I need to turn it to a text string in the excel file ? or using python ?

– ZAKARIA
Mar 8 at 23:01



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55071712%2fcolumn-with-a-fixed-number-of-numbers%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

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved