Drop columns only with 0's
df .loc [:, (df != 0 ).any (axis = 0 )]
df .loc [~ (df == 0 ).all (axis = 1 )]
df = df .rename_axis (None , axis = 1 )
df [col ] = df [col ].str .rstrip ('%' ).astype ('float' ) / 100.0
df .loc [:,'Total' ] = df .sum (numeric_only = True , axis = 1 )
Count positive values per:
# row
df ["Counts" ] = len (df .columns ) - df .apply (lambda row : sum (row [0 :]== 0 ) ,axis = 1 )
# column
df .loc ["Counts" ,:] = len (df .index ) - df .apply (lambda column : sum (column [0 :]== 0 ) ,axis = 0 )
Change display number of rows or columns:
pd .set_option ('display.max_rows' , 1000 )
pd .set_option ('display.max_columns' , 1000 )
to remove SettingWithCopyWarning:
pd .set_option ('mode.chained_assignment' , None )
To remove possible whitespaces (tabs) on the dataframe:
df = df .apply (lambda x : x .str .strip () if x .dtype == "object" else x )
cols = df .columns .tolist ()
print (cols )
cols = list (df .columns )
print ('", "' .join (cols ))
statistics = df .describe ().loc [["mean" , "std" , "min" , "25%" , "50%" , "75%" , "max" ]].round (2 )
with open (args .taxonomy , "r+" ) as f :
lines = f .readlines ()
f .close ()
if x not in d .keys ():
d [x ] = y
elif x in d .keys ():
d [x ].append (y )
Script with pass arguments
import argparse
parser = argparse .ArgumentParser (description = 'Move bins according to taxonomy' )
parser .add_argument ("taxonomy" , help = "File with gtdb result" )
args = parser .parse_args ()
print ("\n " )
print ("Using:" )
print ("~ Taxonomy: {}" .format (args .taxonomy ))