Consider df
:
In [2098]: df = pd.DataFrame({'a': [1,2], 'b':[3,4]})
In [2099]: df
Out[2099]:
a b
0 1 3
1 2 4
Now, I try to append a list
of values to df
:
In [2102]: df.loc[2] = [3, 4]
In [2103]: df
Out[2103]:
a b
0 1 3
1 2 4
2 3 4
All's good so far.
But now when I try to append a row with list of boolean values, it converts it into int
:
In [2104]: df.loc[3] = [True, False]
In [2105]: df
Out[2105]:
a b
0 1 3
1 2 4
2 3 4
3 1 0
I know I can convert my df
into str
and can then append boolean values, like:
In [2131]: df = df.astype(str)
In [2133]: df.loc[3] = [True, False]
In [2134]: df
Out[2134]:
a b
0 1 3
1 2 4
3 True False
But, I want to know the reason behind this behaviour. Why is it not automatically changing the dtypes
of columns to object
when I append boolean
to it?
My Pandas version is:
In [2150]: pd.__version__
Out[2150]: '1.1.0'