def dcounts ( self ) : print ( "WARNING: Distinct value count for all tables can take a long time..." , file = sys . stderr ) sys . stderr . flush ( ) data = [ ] for t in self . tables ( ) : for c in t . columns ( ) : data . append ( [ t . name ( ) , c . name ( ) , c . dcount ( ) , t . size ( ) , c . dcount ( ) / float ( t . size ( ) ) ] ) df = pd . DataFrame ( data , columns = [ "table" , "column" , "distinct" , "size" , "fraction" ] ) return df
python panda how to column counts and turn them into a df
: return : a data frame with names and distinct counts and fractions for all columns in the database
def dcounts(self):
        """
        :return: a data frame with names and distinct counts and fractions for all columns in the database
        """
        print("WARNING: Distinct value count for all tables can take a long time...", file=sys.stderr)
        sys.stderr.flush()

        data = []
        for t in self.tables():
            for c in t.columns():
                data.append([t.name(), c.name(), c.dcount(), t.size(), c.dcount() / float(t.size())])
        df = pd.DataFrame(data, columns=["table", "column", "distinct", "size", "fraction"])
        return df