While reading an Excel file in Python, why is the datatype getting changed from number(int) to object?









up vote
0
down vote

favorite












I have a dataframe Outlet_df derived from an excel file where the column Sellthru Qty only has integer values.



outlet_df = pd.read_excel('BW_CPFR_OUTLET_HU10.xlsx', sheetname='Sheet1')

outlet_df_1 = outlet_df[['Calendar Year/Week','Material','Sellthru Qty']]

outlet_df_1.dtypes


Output



Calendar Year/Week float64
Material object
Sellthru Qty object
dtype: object


The problem is I have to do calculations with the Sellthru Qty. I can't do it if the datatype assigned is not number.



Is there any way around this?










share|improve this question























  • How is Sellthru Qty formatted in the sheet? Can you show some sample data? You may need an .astype conversion on the column.
    – QHarr
    Nov 10 at 22:22











  • I really don't know how to share the excel data formatting here. All values in the column are numbers. For now, I have found a way around using this code: outlet_df_1 = outlet_df_1.convert_objects(convert_numeric=True) But I would like to know how to avoid this issue in the first place. Could you elaborate a bit more about the .astype conversion? Thanks
    – rahul
    Nov 11 at 5:17










  • Its a type casting function. You could include an image of part of the column and tell us when you right click format cells on a cell in the target column how it is formatted.
    – QHarr
    Nov 11 at 5:36







  • 1




    The format is General. Values are all numbers. I don't want to change anything in the Excel file; I want to work on Python only (it's an automation project). The code that I am using works fine. If there is a better way, please let me know.
    – rahul
    Nov 11 at 7:53














up vote
0
down vote

favorite












I have a dataframe Outlet_df derived from an excel file where the column Sellthru Qty only has integer values.



outlet_df = pd.read_excel('BW_CPFR_OUTLET_HU10.xlsx', sheetname='Sheet1')

outlet_df_1 = outlet_df[['Calendar Year/Week','Material','Sellthru Qty']]

outlet_df_1.dtypes


Output



Calendar Year/Week float64
Material object
Sellthru Qty object
dtype: object


The problem is I have to do calculations with the Sellthru Qty. I can't do it if the datatype assigned is not number.



Is there any way around this?










share|improve this question























  • How is Sellthru Qty formatted in the sheet? Can you show some sample data? You may need an .astype conversion on the column.
    – QHarr
    Nov 10 at 22:22











  • I really don't know how to share the excel data formatting here. All values in the column are numbers. For now, I have found a way around using this code: outlet_df_1 = outlet_df_1.convert_objects(convert_numeric=True) But I would like to know how to avoid this issue in the first place. Could you elaborate a bit more about the .astype conversion? Thanks
    – rahul
    Nov 11 at 5:17










  • Its a type casting function. You could include an image of part of the column and tell us when you right click format cells on a cell in the target column how it is formatted.
    – QHarr
    Nov 11 at 5:36







  • 1




    The format is General. Values are all numbers. I don't want to change anything in the Excel file; I want to work on Python only (it's an automation project). The code that I am using works fine. If there is a better way, please let me know.
    – rahul
    Nov 11 at 7:53












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a dataframe Outlet_df derived from an excel file where the column Sellthru Qty only has integer values.



outlet_df = pd.read_excel('BW_CPFR_OUTLET_HU10.xlsx', sheetname='Sheet1')

outlet_df_1 = outlet_df[['Calendar Year/Week','Material','Sellthru Qty']]

outlet_df_1.dtypes


Output



Calendar Year/Week float64
Material object
Sellthru Qty object
dtype: object


The problem is I have to do calculations with the Sellthru Qty. I can't do it if the datatype assigned is not number.



Is there any way around this?










share|improve this question















I have a dataframe Outlet_df derived from an excel file where the column Sellthru Qty only has integer values.



outlet_df = pd.read_excel('BW_CPFR_OUTLET_HU10.xlsx', sheetname='Sheet1')

outlet_df_1 = outlet_df[['Calendar Year/Week','Material','Sellthru Qty']]

outlet_df_1.dtypes


Output



Calendar Year/Week float64
Material object
Sellthru Qty object
dtype: object


The problem is I have to do calculations with the Sellthru Qty. I can't do it if the datatype assigned is not number.



Is there any way around this?







excel python-2.7 dataframe






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 20:05

























asked Nov 10 at 15:56









rahul

122




122











  • How is Sellthru Qty formatted in the sheet? Can you show some sample data? You may need an .astype conversion on the column.
    – QHarr
    Nov 10 at 22:22











  • I really don't know how to share the excel data formatting here. All values in the column are numbers. For now, I have found a way around using this code: outlet_df_1 = outlet_df_1.convert_objects(convert_numeric=True) But I would like to know how to avoid this issue in the first place. Could you elaborate a bit more about the .astype conversion? Thanks
    – rahul
    Nov 11 at 5:17










  • Its a type casting function. You could include an image of part of the column and tell us when you right click format cells on a cell in the target column how it is formatted.
    – QHarr
    Nov 11 at 5:36







  • 1




    The format is General. Values are all numbers. I don't want to change anything in the Excel file; I want to work on Python only (it's an automation project). The code that I am using works fine. If there is a better way, please let me know.
    – rahul
    Nov 11 at 7:53
















  • How is Sellthru Qty formatted in the sheet? Can you show some sample data? You may need an .astype conversion on the column.
    – QHarr
    Nov 10 at 22:22











  • I really don't know how to share the excel data formatting here. All values in the column are numbers. For now, I have found a way around using this code: outlet_df_1 = outlet_df_1.convert_objects(convert_numeric=True) But I would like to know how to avoid this issue in the first place. Could you elaborate a bit more about the .astype conversion? Thanks
    – rahul
    Nov 11 at 5:17










  • Its a type casting function. You could include an image of part of the column and tell us when you right click format cells on a cell in the target column how it is formatted.
    – QHarr
    Nov 11 at 5:36







  • 1




    The format is General. Values are all numbers. I don't want to change anything in the Excel file; I want to work on Python only (it's an automation project). The code that I am using works fine. If there is a better way, please let me know.
    – rahul
    Nov 11 at 7:53















How is Sellthru Qty formatted in the sheet? Can you show some sample data? You may need an .astype conversion on the column.
– QHarr
Nov 10 at 22:22





How is Sellthru Qty formatted in the sheet? Can you show some sample data? You may need an .astype conversion on the column.
– QHarr
Nov 10 at 22:22













I really don't know how to share the excel data formatting here. All values in the column are numbers. For now, I have found a way around using this code: outlet_df_1 = outlet_df_1.convert_objects(convert_numeric=True) But I would like to know how to avoid this issue in the first place. Could you elaborate a bit more about the .astype conversion? Thanks
– rahul
Nov 11 at 5:17




I really don't know how to share the excel data formatting here. All values in the column are numbers. For now, I have found a way around using this code: outlet_df_1 = outlet_df_1.convert_objects(convert_numeric=True) But I would like to know how to avoid this issue in the first place. Could you elaborate a bit more about the .astype conversion? Thanks
– rahul
Nov 11 at 5:17












Its a type casting function. You could include an image of part of the column and tell us when you right click format cells on a cell in the target column how it is formatted.
– QHarr
Nov 11 at 5:36





Its a type casting function. You could include an image of part of the column and tell us when you right click format cells on a cell in the target column how it is formatted.
– QHarr
Nov 11 at 5:36





1




1




The format is General. Values are all numbers. I don't want to change anything in the Excel file; I want to work on Python only (it's an automation project). The code that I am using works fine. If there is a better way, please let me know.
– rahul
Nov 11 at 7:53




The format is General. Values are all numbers. I don't want to change anything in the Excel file; I want to work on Python only (it's an automation project). The code that I am using works fine. If there is a better way, please let me know.
– rahul
Nov 11 at 7:53

















active

oldest

votes











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%2f53240687%2fwhile-reading-an-excel-file-in-python-why-is-the-datatype-getting-changed-from%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240687%2fwhile-reading-an-excel-file-in-python-why-is-the-datatype-getting-changed-from%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







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto