问题描述
将熊猫系列 s
映射到数据框 x
时,我收到 SettingWithcopy 警告:
s.head()
84 2013-06-05 10:20:29
87 2013-06-05 15:27:56
469 2013-06-28 03:20:05
4670 2013-11-15 11:10:48
4673 2013-11-15 14:08:01
Name: timestamp,dtype: datetime64[ns]
y.head()
min max
0 2013-06-02 09:10:51 2013-06-02 10:27:44
1 2013-06-12 03:08:35 2013-06-12 03:08:35
2 2013-08-03 09:11:35 2021-01-26 23:05:17
x.head()
timestamp
4 2013-06-01 04:12:34
5 2013-06-01 04:19:08
6 2013-06-01 05:18:35
7 2013-06-01 06:00:19
8 2013-06-01 09:16:13
dfo = x.assign(a=1).merge(y.assign(a=1),on='a')
s = df.loc[(dfo['min']<=dfo['timestamp']) & (dfo['max']>=dfo['timestamp']),'timestamp']
x['count']=x['timestamp'].map(s.value_counts()).fillna(0).astype(int)
<ipython-input-205-91489a4af264>:1: SettingWithcopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
由于我正在基于系列地图创建一个新列,为什么会抛出错误(复制的切片是什么?)以及使用 i.loc
重写它的正确方法是什么,因为我没有使用索引器?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)