missing-data
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
Python, Pandas : Return only those rows which have missing values
You can use any axis=1 to check for least one True per row, then filter with boolean indexing: null_data = df[df.isnull().any(axis=1)]
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
Delete rows with blank values in one particular column
df[!(is.na(df$start_pc) | df$start_pc==””), ]
Elegant way to report missing values in a data.frame
Just use sapply > sapply(airquality, function(x) sum(is.na(x))) Ozone Solar.R Wind Temp Month Day 37 7 0 0 0 0 You could also use apply or colSums on the matrix created by is.na() > apply(is.na(airquality),2,sum) Ozone Solar.R Wind Temp Month Day 37 7 0 0 0 0 > colSums(is.na(airquality)) Ozone Solar.R Wind Temp Month Day 37 … Read more
str.format() raises KeyError
The problem is that those { and } characters you have there don’t specify a key for formatting. You need to double them up, so change your code to: addr_list_formatted.append(“”” “{0}” {{ “gamedir” “str” “address” “{1}” }} “””.format(addr_list_idx, addr))
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