TypeError: ufunc ‘isnan’ not supported for the input types, and the inputs could not be safely coerced

Posting as it might help future users. As correctly pointed out by others, np.isnan won’t work for object or string dtypes. If you’re using pandas, as mentioned here you can directly use pd.isnull, which should work in your case. import pandas as pd import numpy as np var1 = ” var2 = np.nan >>> type(var1) … Read more

Format string unused named arguments [duplicate]

If you are using Python 3.2+, use can use str.format_map(). For bond, bond: from collections import defaultdict ‘{bond}, {james} {bond}’.format_map(defaultdict(str, bond=’bond’)) Result: ‘bond, bond’ For bond, {james} bond: class SafeDict(dict): def __missing__(self, key): return ‘{‘ + key + ‘}’ ‘{bond}, {james} {bond}’.format_map(SafeDict(bond=’bond’)) Result: ‘bond, {james} bond’ In Python 2.6/2.7 For bond, bond: from collections import … Read more

Remove rows with all or some NAs (missing values) in data.frame

Also check complete.cases : > final[complete.cases(final), ] gene hsap mmul mmus rnor cfam 2 ENSG00000199674 0 2 2 2 2 6 ENSG00000221312 0 1 2 3 2 na.omit is nicer for just removing all NA‘s. complete.cases allows partial selection by including only certain columns of the dataframe: > final[complete.cases(final[ , 5:6]),] gene hsap mmul mmus … Read more