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?
excel python-2.7 dataframe
add a comment |
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?
excel python-2.7 dataframe
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
add a comment |
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?
excel python-2.7 dataframe
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
excel python-2.7 dataframe
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
add a comment |
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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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 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