简体   繁体   中英

iterate through dataframe columns and determine which are numeric

I have a read data from from a csv file. I'd like to write code that does the following—

(1) starts iterating through each column (I imagine a for loop)

(2) determines if a column contains only numbers

(3) if the column is numeric, print certain statistical information about that specific column & whether that column is normally distributed (skewness & kurtosis between -1 and 1)

(4) if the column is not numeric, skip over it

This is for an Intro Python course, so it is not expected to be complex

So far this is my code:

import pandas as pd

df = pd.read_csv('file path')

columns = list(df)

for i in columns:
(if column is numeric, print: Column Title, min, max, mean, median, "Yes column normal" or "No column not normal")
(else, just skip it)
for column in df: 
    if np.issubdtype(df[column], np.number): 
        print(df[column]) # print(df[column].describe()) or whatever other stats

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM