-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
Closed
Labels
BugNested DataData where the values are collections (lists, sets, dicts, objects, etc.).Data where the values are collections (lists, sets, dicts, objects, etc.).Stylerconditional formatting using DataFrame.styleconditional formatting using DataFrame.style
Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
pd.DataFrame([dict(a=1, b=[1, 2, 3])]).style.format(na_rep="-").to_html()
# ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()Issue Description
.style.format()'s na_rep is not compatible with non-scalar elements like lists. The problem seems to be that isna(obj) does not return a boolean in this case.
Expected Behavior
format(na_rep="-") should have the intended behaviour of styling using "-" if there is no object in the "b" column, and styling it as usual otherwise.
Note that pd.isna(pd.DataFrame([dict(a=1, b=[1, 2, 3])])) runs without error.
Installed Versions
Details
commit : 4bfe3d07b4858144c219b9346329027024102ab6
python : 3.8.10.final.0
python-bits : 64
OS : Linux
OS-release : 5.13.0-41-generic
Version : #46~20.04.1-Ubuntu SMP Wed Apr 20 13:16:21 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : sv_SE.UTF-8
LOCALE : sv_SE.UTF-8
pandas : 1.4.2
numpy : 1.22.4
pytz : 2022.1
dateutil : 2.8.2
pip : 20.0.2
setuptools : 44.0.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
markupsafe : 2.1.1
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
PROrock
Metadata
Metadata
Assignees
Labels
BugNested DataData where the values are collections (lists, sets, dicts, objects, etc.).Data where the values are collections (lists, sets, dicts, objects, etc.).Stylerconditional formatting using DataFrame.styleconditional formatting using DataFrame.style