I want to display all my column with the dtypes.
For this I used to do df.dtypes. But in this dataframe I have 4000 column and I would also like to number them.
I tried something like this:
for i in range(df.shape[1]):
with pd.option_context('display.max_rows', None, 'display.max_columns', None):
print(i ,':',df.dtypes)
This obviously does not give me the expected result but you get the idea of what I need. How can I can use df.dtypes in a loop?
>Solution :
you can try this:
for i in range(df.shape[1]):
with pd.option_context('display.max_rows', None, 'display.max_columns', None):
print(i ,':',df.iloc[:,i].dtypes)
If you want column name also, then try this:
for i in range(df.shape[1]):
with pd.option_context('display.max_rows', None, 'display.max_columns', None):
print(i ,':',df.columns[i],df.iloc[:,i].dtypes)