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