我试图在对两列进行子集设置后对熊猫数据帧重新采样。下面是数据帧的头部。两列都是熊猫系列
temp_2011_clean[['visibility', 'dry_bulb_faren']].head()
visibility dry_bulb_faren
2011-01-01 00:53:00 10.00 51.0
2011-01-01 01:53:00 10.00 51.0
2011-01-01 02:53:00 10.00 51.0
2011-01-01 03:53:00 10.00 50.0
2011-01-01 04:53:00 10.00 50.0
type(temp_2011_clean['visibility'])
pandas.core.series.Series
type(temp_2011_clean['dry_bulb_faren'])
pandas.core.series.Series
虽然.resample('W')方法成功地创建了重采样对象,但如果我将.mean()方法链接到同一个对象,它只拾取一列,而不是预期的两列。有人能提出什么问题吗?为什么少了一列
temp_2011_clean[['visibility', 'dry_bulb_faren']].resample('W')
<pandas.core.resample.DatetimeIndexResampler object at 0x0000016F4B943288>
temp_2011_clean[['visibility', 'dry_bulb_faren']].resample('W').mean().head()
dry_bulb_faren
2011-01-02 44.791667
2011-01-09 50.246637
2011-01-16 41.103774
2011-01-23 47.194313
2011-01-30 53.486188
我认为问题应该是
visibility
列不是数字,所以非数字列被排除在外因此,通过^{} 和
errors='coerce'
将列转换为数值,以便将非数值转换为NaN
:相关问题 更多 >
编程相关推荐