I'm trying to apply a function to every element in a column but I keep getting this error and I'm not sure how to fix it.
Code:
import pandas as pd
import pubchempy
import numpy as np
df = pd.read_csv("Data.tsv.txt", sep="\t")
.
.
.
df['CID'] = df['CID'].astype(str).apply(lambda x: x.replace('.0',''))
df['CID']= df['CID'].map(lambda x: get_properties(identifier=x, properties='MolecularWeight') if x>0 else pd.NA)
Error:
TypeError: '>' not supported between instances of 'str' and 'int'
Also, the get_properties() function is a function from pubchempy that takes the requested information (in this case, 'MolecularWeight') directly from the pubchem website.
The inputs are:
pubchempy.get_compounds(identifier, namespace=u'cid', searchtype=None, as_dataframe=False, **kwargs)
Only the properties and identifier parameters are required, the rest are optional.
Thanks in advance!