我有一個具有很少功能的 data_frame "x"。我想計算每個功能的最小值、最大值、數據類型等并存儲到我的新 DF。下面是我的代碼片段:import panda as pd import numpy as nstats = pd.DataFrame(columns=["Type", "Min", "Max", "Mean", "Std"])for col in x.columns: stats.loc[col] = {"Type": x[col].dtypes, "Min": x[col].min(), "Max": x[col].max(), }出現錯誤:無法設置列不匹配的行讓我知道任何建議
1 回答
藍山帝景
TA貢獻1843條經驗 獲得超7個贊
如果您只想快速查看數據框,請調用 x。描述(),這將為您提供均值,標準差,最小值和最大值等。
如果你真的想為每一列存儲這些數據,你可以像這樣構建它:
stats = pd.DataFrame()
stats.insert(0, 'Type', x.dtypes)
stats.insert(0, 'Min', x.min())
stats.insert(0, 'Max', x.max())
etc...
添加回答
舉報
0/150
提交
取消
