2

So i am reading a .xlsx file and i need to check how many variables in the xlsx file belong to each datatype in pandas and finally export it to excel.

So here is the code :

sheet = pd.read_excel(r"D:\Users\850034535\AnacondaProjects\Jupyter Project\Sample.xlsx",sheetname=2)
alldtypes = sheet.dtypes.value_counts()
alldtypes_df = list_of_all_variables.to_frame()
alldtypes_df.to_excel('123.xlsx')

This code gives an error: " TypeError: float() argument must be a string or a number, not 'numpy.dtype' "

So then i converted the dataframe to str type, so now an additional line of code was added :

 alldtypes_df = alldtypes_df.applymap(str)

But still it is showing me the same error and the error given in the title.

Any suggestions would be much appreciated.

1 Answer 1

2

It seems need convert index to strings:

alldtypes_df.index = alldtypes_df.index.astype(str)
Sign up to request clarification or add additional context in comments.

2 Comments

Worked Flawlessly, Thanks a lot!!
@explorer_x - Glad can help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.