python 尋找list中最大值、最小值位置; reshpe(-1,1)提示,格式話出錯,pandas copy
阿新 • • 發佈:2018-12-13
1:尋找list中最大值、最小值位置
轉載自:https://blog.csdn.net/fengjiexyb/article/details/77435676
c = [-10,-5,0,5,3,10,15,-20,25]
print c.index(min(c)) # 返回最小值
print c.index(max(c)) # 返回最大值
2:報錯 Reshape your data either using array.reshape(-1, 1)
訓練數劇維度和模型要求不一致會報這個錯誤,我是在講一個特徵進行訓練時得到這個錯誤,rf模型,提示要加reshape(-1,1),最新版本要求values.reshape()
rf.fit(X_train.iloc[:, tmp_list].values.reshape(-1, 1), y_train)
3:python 列印格式話輸出的時候,替換部分要加()
“%s %s” % (value1,value2)
for i,s in enumerate(feature_indexs):
print("%s %s %s \n" % (s, pd_data.columns.values[s],final_score[i]))
4:pandas 深度copy
DataFrame.copy(deep=True)
>>> s = pd.Series([1, 2], index=["a", "b"]) >>> s a 1 b 2 dtype: int64 >>> s_copy = s.copy() >>> s_copy a 1 b 2 dtype: int64 Shallow copy versus default (deep) copy: >>> s = pd.Series([1, 2], index=["a", "b"]) >>> deep = s.copy() >>> shallow = s.copy(deep=False) Shallow copy shares data and index with original. >>> s is shallow False >>> s.values is shallow.values and s.index is shallow.index True Deep copy has own copy of data and index. >>> s is deep False >>> s.values is deep.values or s.index is deep.index False Updates to the data shared by shallow copy and original is reflected in both; deep copy remains unchanged. >>> s[0] = 3 >>> shallow[1] = 4 >>> s a 3 b 4 dtype: int64 >>> shallow a 3 b 4 dtype: int64 >>> deep a 1 b 2 dtype: int64