0

For all columns in enrichr_genes that are "None", I replace them with 0 before matching it against the column value of another data frame meth_all.

enrichr_genes = enrichr_genes.fillna(0)

for col in enrichr_genes.itertuples():
    if col == meth_all["Target"]:
        print(col)

Traceback:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/tmp/ipykernel_27/2393237721.py in <module>
      1 for col in enrichr_genes.itertuples():
----> 2     if col == meth_all["Target"]:
      3         print(col)

/opt/conda/lib/python3.7/site-packages/pandas/core/generic.py in __nonzero__(self)
   1536     def __nonzero__(self):
   1537         raise ValueError(
-> 1538             f"The truth value of a {type(self).__name__} is ambiguous. "
   1539             "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
   1540         )

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

meth_all example:

meth_all = pd.DataFrame([['ZNF529', 'ZNF382', 221.7682346300719],
       ['WT1', 'WIT1', 114.35710729484111],
       ['HOXB4', 'MIR10A', 100.56988297891884],
       ['ZNF275', 'ZNF81', 95.52091653099176],
       ['ZNF583', 'ZCCHC17', 94.95539553164043],
       ['ZNF275', 'EMD', 93.88332290413156],
       ['ZNF674', 'TAZ', 93.86801400448093],
       ['HMGB3', 'PDK3', 93.0093474028802],
       ['ZNF81', 'VBP1', 91.90313302398322]], dtype=object, columns=["TF", "Target", "Importance"])

enrichr_gene example:

enrichr_gene = pd.DataFrame([['ADCY2', 'OPRM1', 'ADCY7', 'GNAI1', 'GNAI2', 'GNAO1', 'CREB1',
        'PRKAR2B', 'PRKAR2A'],
       ['PRKAR2B', 'PRKAR2A', 'ADCY2', 'PRKACA', 'PRKACB', 'ADCY7', None, None,
        None],
       ['ATP5A1', 'ATP5C1', 'CYCS', None, None, None, None, None, None],
       ['MTHFD2', 'MTR', 'TYMS', None, None, None, None, None, None],
       ['HPRT1', 'ADA', 'APRT', None, None, None, None, None, None],
       ['GOT1', 'GOT2', 'ASNS', None, None, None, None, None, None],
       ['PC', 'PDHA1', 'PKLR', 'ME1', 'PCK1', None, None, None, None],
       ['CYP27B1', 'CYP27C1', 'CYP24A1', 'VDR', 'GC', None, None, None, None],
       ['SHMT1', 'PHGDH', 'PSPH', None, None, None, None, None, None],
       ['FECH', 'QARS', 'UROD', 'HMBS', 'EPRS', 'EARS2', None, None, None]],
      dtype=object)

I know the sample data might not be the most suitable for the question. Sorry!

melolilili
  • 239
  • 1
  • 8
  • The issue is not the NaN, it is that `if ...` expectes a single boolean while `col == meth_all["Target"]` gives a **Series** of booleans, which is ambiguous. – mozway Oct 23 '22 at 19:35

0 Answers0