When a series has dtype="object"
, series.iloc[0] = {}
converts the series element to a pandas Series
, instead of storing the dictionary:
import pandas
s = pandas.Series(0, dtype="object")
s[0] = {}
assert s[0] == {} # passes
s.iloc[0] = {}
assert s[0] == {} # fails
I was surprised by this behavior, because I expected that dtype="object"
would let me store the actual dictionary inside the series.
If this is expected behavior, I'd love to know if there's a recommended way to store dictionary values inside of a object-dtype series without it being converted.