[英]iterate through dataframe columns and determine which are numeric
我有一個來自 csv 文件的讀取數據。 我想編寫執行以下操作的代碼 -
(1) 開始遍歷每一列(我想象一個 for 循環)
(2) 確定一列是否只包含數字
(3) 如果該列是數字,則打印有關該特定列的某些統計信息以及該列是否呈正態分布(偏度和峰度介於 -1 和 1 之間)
(4) 如果該列不是數字,則跳過它
這是 Python 入門課程,因此預計不會很復雜
到目前為止,這是我的代碼:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.