.. _f-tableformula: module ``homeblog.table_formula`` ================================= .. inheritance-diagram:: ensae_teaching_cs.homeblog.table_formula Short summary +++++++++++++ module ``ensae_teaching_cs.homeblog.table_formula`` Implements TableFormula. :githublink:`%|py|0` Classes +++++++ +-------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------+ | class | truncated documentation | +===============================================================================+===============================================================================================================================+ | :class:`TableFormula ` | This class aims at representating a table, it provides some "SQL like" functionalities such groupby or innerjoin, select, ... | +-------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------+ Properties ++++++++++ +-------------------------------------------------------------------------------------+---------------------------------------+ | property | truncated documentation | +=====================================================================================+=======================================+ | :meth:`dataframe ` | creates a pandas dataframe | +-------------------------------------------------------------------------------------+---------------------------------------+ | :meth:`json ` | returns a json format | +-------------------------------------------------------------------------------------+---------------------------------------+ | :meth:`np_array ` | returns the values as a numpy array | +-------------------------------------------------------------------------------------+---------------------------------------+ | :meth:`np_matrix ` | returns the values as a numpy matrix | +-------------------------------------------------------------------------------------+---------------------------------------+ | :meth:`shape ` | returns the size(nb rows, nb columns) | +-------------------------------------------------------------------------------------+---------------------------------------+ | :meth:`size ` | returns the size(nb rows, nb columns) | +-------------------------------------------------------------------------------------+---------------------------------------+ Static Methods ++++++++++++++ +---------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | staticmethod | truncated documentation | +=====================================================================================================================+======================================================================================================================+ | :meth:`add_header_if_not_present ` | the function checks if the first line contains the column in header otherwise, it modifies the file and add them ... | +---------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`bootstrap ` | return a confidence interval for a statistics | +---------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`correlation_bicolumn ` | assume values is a matrix with two columns | +---------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`random_split_file ` | split a file in nb buckets by random(lines are sent to a random file as they come) | +---------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`ratio ` | return a ratio between two real values or an empty string if the denominateur is null | +---------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`save_multiple_as_excel ` | saves multiple table in one Excel file | +---------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ Methods +++++++ +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | method | truncated documentation | +=================================================================================================================================+======================================================================================================================+ | :py:meth:`__add__ ` | do an addition, add values if types are matching | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :py:meth:`__copy__ ` | operator copy | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :py:meth:`__deepcopy__ ` | operator ``deepcopy`` | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :py:meth:`__eq__ ` | check if two tables are equal by value | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :py:meth:`__getitem__ ` | operator [], accepts slices | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :py:meth:`__html__ ` | Converts the table into a :epkg:`html` string. | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :py:meth:`__init__ ` | It can either take a filename, an object TableFormula, a list of columns and values. | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :py:meth:`__iter__ ` | iterator on all rows, it returns a dictionary { column:value } | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :py:meth:`__len__ ` | returns the number of rows | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :py:meth:`__mul__ ` | do a multiplication(by a number) | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :py:meth:`__rst__ ` | convert the table into rst format | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :py:meth:`__setitem__ ` | operator [], just accepts tuple(to change a value) | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :py:meth:`__str__ ` | convert the table into a string | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :py:meth:`_auto_conversion ` | private set up the column type based on the column name | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :py:meth:`_fill_by_row ` | fill the table | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :py:meth:`_interpret_row ` | private returns each row as a dictionary { column_name:value } | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :py:meth:`_private_getclass ` | the class often creates another class of the same type, this function returns the class object | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :py:meth:`_read_file ` | private | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :py:meth:`_readlines ` | private | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`add_column ` | Adds a column. | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`add_column_cumulative ` | also called the Gini function Example: | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`add_column_index ` | Example: | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`add_column_recursive ` | Example: | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`add_column_recursive_row ` | Example: | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`add_column_smooth ` | Example: | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`add_column_vector ` | add a column defined by vector(list of values for each row) | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`addc ` | @see me add_column | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`aggregate ` | Example: | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`aggregate_column ` | Example: | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`avg_std ` | returns the average and standard deviation | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`center_reduce ` | center and reduce a set of columns(or all if columnsSet is None) | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`change_header ` | change the column names | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`concatenate ` | concatenates two tables by columns | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`copy ` | call ``copy.deepcopy(self)`` | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`correlation ` | Computes the correlation matrix, the first column will contains the column names. | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`correlation_col ` | Computes the correlation between two columns. | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`correlation_row ` | computes the correlation between two columns | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`covariance ` | Computes the covariance matrix, the first column will contains the column names. | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`covariance_col ` | Computes the correlation between two columns. | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`covariance_row ` | computes the correlation between two columns | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`create_index ` | this method creates an index, to get an indexes row, use method get Example: | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`dcast ` | @see me multiply_column_by_row_instance | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`delta ` | returns a list of differences between self and others | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`extract_columns ` | extract some columns | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`fill_sql_table ` | returns a Database object, creates the database if it does not exists, same for the table | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`filter ` | Example: | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`filter_quantile ` | sort all rows using criteria defined by function and remove rows at the extremes | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`get ` | use the index created by method create_index Example: | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`get_column_values ` | private returns all values for one column | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`get_distinct_values ` | private | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`groupby ` | Example: | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`groupby_implicit ` | use prefix of a column name to know which function to use as an aggregated(sum, avg, len, key, none, max, min) ... | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`histogram ` | computes an histograms on one vector | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`histograms ` | computes a common histograms on all columns | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`innerjoin ` | | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`modify_all ` | apply the same modification to every number | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`mu_sigma ` | computes the average and the standard deviation a vector of values | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`mu_sigma_each_column ` | returns a table with the average and the standard deviation for each columns | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`multiplication_term_term ` | do a multiplication term by term(similar to an addition), add values if types are matching | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`multiply_column_by_row_instance ` | | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`random ` | select n random row from the table, returns a table | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`reduce_dict ` | @see me todict | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`remove_columns ` | remove some columns | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`rename_column ` | rename a column | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`replicate ` | replicates all rows a given number of times | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`save ` | saves the tables in a text file, first row is the column names | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`save_as_excel ` | saves the table as a new Excel file, you can use ``.xls`` or ``.xlsx`` if filename is None, the function returns ... | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`schema_database ` | returns the schema for a database which would contains this database | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`select ` | | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`sort ` | Example: | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`strtype ` | displays the type of values(not the values) | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`todict ` | convert the table as a dictionary { key:value } each of them is defined by functions. | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`transpose ` | Computes the transpose. | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`union ` | | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`union_columns ` | computes the union of all values from all columns present in columnSet | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`values_to_date ` | converts all values into dates | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`values_to_float ` | converts all values into float | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`values_to_str ` | converts all values into str | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :meth:`where ` | @see me filter | +---------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------+ Documentation +++++++++++++ .. automodule:: ensae_teaching_cs.homeblog.table_formula :members: :special-members: __init__ :show-inheritance: