python 寻找list中最大值、最小值位置; reshpe(-1,1)提示,格式话出错,pandas copy深拷贝浅拷贝

27 篇文章 0 订阅
7 篇文章 0 订阅

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值