# dataframe中的列名。
featureList = df.columns
print(featureList)
#number of columns in the dataframe(資料框架的列數
noOfCol = len(df.axes[1] )
print(noOfCol)
#number of rows(行數)。
noOfRow = len(df.axes[0] )
print(noOfRow)
featureList = df.columns
print(featureList)
#number of columns in the dataframe。
noOfCol = len(df.axes[1] )
print(noOfCol)
#number of rows(行數)。
noOfRow = len(df.axes[0] )
print(noOfRow)
#creating a dictionary for storing all the cols separately(nofRow)
#using for loop: way4
dfDic = dict()
colCounter = 0
for featureName in featureList:
dfDic = {featureName:df.iloc[:,[colCounter]]}
colCounter =1
print(dfDic)
這是我的代碼,下面的image是結果。我想存盤所有特征的列值,但只有最后一列被存盤。
uj5u.com熱心網友回復:
你可以簡單地使用df.to_dict(orient="list")將Pandas資料框架轉換為一個字典。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/311631.html
標籤:
