Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas replace nan

data["Gender"].fillna("No Gender", inplace = True) 
Comment

python pandas replace nan with null

df.fillna('', inplace=True)
Comment

pandas where retuning NaN

# Try using a loc instead of a where:
df_sub = df.loc[df.yourcolumn == 'yourvalue']
Comment

pandas convert specific string to NaN

pd.data.replace('?', np.nan)
Comment

turn False to nan pandas

In [1]: df = DataFrame([[True, True, False],[False, False, True]]).T

In [2]: df
Out[2]:
       0      1
0   True  False
1   True  False
2  False   True

In [3]: df.applymap(lambda x: 1 if x else np.nan)
Out[3]:
    0   1
0   1 NaN
1   1 NaN
2 NaN   1
Comment

pandas using eval converter excluding nans

df.fillna('()').applymap(ast.literal_eval)
Comment

pandas using eval converter excluding nans

from ast import literal_eval
from io import StringIO

# replicate csv file
x = StringIO("""A,B
,"('t1', 't2')"
"('t3', 't4')",""")

def literal_converter(val):
    # replace first val with '' or some other null identifier if required
    return val if val == '' else literal_eval(val)

df = pd.read_csv(x, delimiter=',', converters=dict.fromkeys('AB', literal_converter))

print(df)

          A         B
0            (t1, t2)
1  (t3, t4)          
Comment

PREVIOUS NEXT
Code Example
Python :: how to add axis labels to a plotly barchart 
Python :: logging store info to different files 
Python :: check boolean python 
Python :: python MAX_INT 
Python :: .translate python 
Python :: Python List clear() 
Python :: count TRUE in DF 
Python :: how to get parent model object based on child model filter in django 
Python :: argparse type 
Python :: search and replace in python 
Python :: python message 
Python :: graph skewness detection 
Python :: python remove all occurrence of an items from list 
Python :: check if string is python code 
Python :: python regex (d)(?=d1) 
Python :: operator overloading python 
Python :: python arrow 
Python :: string slice python 
Python :: removing stop words from the text 
Python :: euclidean distance 
Python :: python list remove() 
Python :: determine how 2 string si equal py 
Python :: Python NumPy delete Function Example Deletion from 1D array 
Python :: pyspark on colab 
Python :: append element to list py 
Python :: pandas df number of columns 
Python :: regex python 
Python :: Python NumPy ravel function Syntax 
Python :: python string to uppercase 
Python :: how to remove outliers in dataset in python 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =