为什么数据帧和系列之间的运算符“*”给我一个带有 NaN 的 len(firstSeries)*len(secondSeries)?

Why the operator "*" between a dataframe and a series is giving me a len(firstSeries)*len(secondSeries) with NaNs?

我得到 res = dataframe * dataframe['column'] 第一个数据帧 <class 'pandas.core.frame.DataFrame'><class 'pandas.core.series.Series'> dataframe['column']

它输出我: res : 2020-08-17 05:00:00 2020-08-17 05:15:00 2020-08-17 05:30:00 ... dtime 2020-08-24 16:45:00 NaN NaN NaN ... 2020-08-24 16:30:00 NaN NaN NaN ... 2020-08-24 16:15:00 NaN NaN NaN ... 2020-08-24 16:00:00 NaN NaN NaN ... 2020-08-24 15:45:00 NaN NaN NaN ... ... 2020-08-17 06:00:00 NaN NaN NaN ... 2020-08-17 05:45:00 NaN NaN NaN ... 2020-08-17 05:30:00 NaN NaN NaN ... 2020-08-17 05:15:00 NaN NaN NaN ... 2020-08-17 05:00:00 NaN NaN NaN ...

我发现的一切都告诉我“*”应该给我:res : dtime 2020-08-24 16:45:00 floatValue 2020-08-24 16:30:00 floatValue 2020-08-24 16:15:00 floatValue 2020-08-24 16:00:00 floatValue 2020-08-24 15:45:00 floatValue ... 2020-08-17 06:00:00 floatValue 2020-08-17 05:45:00 floatValue 2020-08-17 05:30:00 floatValue 2020-08-17 05:15:00 floatValue 2020-08-17 05:00:00 floatValue

我确定我遗漏了什么,但我找不到什么。

编辑:

import pandas
df = pandas.DataFrame({"angles": [0, 3, 4], "degrees": [360, 180, 360]}, index=["circle", "triangle", "rectangle"])
other = pandas.DataFrame({"angles": [0, 3, 4]}, index=["circle", "triangle", "rectangle"])
print("df * other :", df * other)

给我:

df * other :
           angles  degrees
circle          0      NaN
triangle        9      NaN
rectangle      16      NaN

符合预期。所以也许它与 datetimeIndex 有关。

编辑:

import pandas

df = pandas.DataFrame({'angles': [0, 3, 4], 'degrees': [360, 180, 360]}, index=['2020-08-17 05:30:00', '2020-08-17 05:15:00', '2020-08-17 05:00:00'])
other = pandas.DataFrame({'angles': [0, 3, 4]}, index=['2020-08-17 05:30:00', '2020-08-17 05:15:00', '2020-08-17 05:00:00'])
df.index = pandas.to_datetime(df.index, format='%Y-%m-%d %H:%M:%S')
other.index = pandas.to_datetime(other.index, format='%Y-%m-%d %H:%M:%S')

print("df * other :", df * other)

正在给予:

df * other :         angles  degrees
2020-08-17 05:30:00       0      NaN
2020-08-17 05:15:00       9      NaN
2020-08-17 05:00:00      16      NaN

所以这不是 datetimeIndex。

在你的小例子中,你乘以 df * df[即其他 ]。如果你使用 df *df.angles [即df * 系列]

但在主要问题中,您使用的是 df * 系列。尝试使用 df * pd.DataFrame(df.col) .

在 df * 系列中:它按列比较与 df.multiply(df.series,axis=1) 相同 你也可以试试 df.multiply(df.series,axis=0)