finpandas.dataframes package

Submodules

finpandas.dataframes.forms module

Abstract data types for US public fundamentals: 10K and 10Q.

class finpandas.dataframes.forms.Form(dataframe: pandas.core.frame.DataFrame)[source]

Bases: pandas.core.frame.DataFrame

Abstract Data Type for SEC forms. Subclass of pandas DataFrame.

property _constructor

Used when a manipulation result has the same dimensions as the original.

property _constructor_expanddim
property _constructor_sliced

One-dimensional ndarray with axis labels (including time series).

Labels need not be unique but must be a hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index. Statistical methods from ndarray have been overridden to automatically exclude missing data (currently represented as NaN).

Operations between Series (+, -, /, , *) align values based on their associated index values– they need not be the same length. The result index will be the sorted union of the two indexes.

dataarray-like, Iterable, dict, or scalar value

Contains data stored in Series. If data is a dict, argument order is maintained.

indexarray-like or Index (1d)

Values must be hashable and have the same length as data. Non-unique index values are allowed. Will default to RangeIndex (0, 1, 2, …, n) if not provided. If data is dict-like and index is None, then the keys in the data are used as the index. If the index is not None, the resulting Series is reindexed with the index values.

dtypestr, numpy.dtype, or ExtensionDtype, optional

Data type for the output Series. If not specified, this will be inferred from data. See the user guide for more usages.

namestr, optional

The name to give to the Series.

copybool, default False

Copy input data. Only affects Series or 1d ndarray input. See examples.

Constructing Series from a dictionary with an Index specified

>>> d = {'a': 1, 'b': 2, 'c': 3}
>>> ser = pd.Series(data=d, index=['a', 'b', 'c'])
>>> ser
a   1
b   2
c   3
dtype: int64

The keys of the dictionary match with the Index values, hence the Index values have no effect.

>>> d = {'a': 1, 'b': 2, 'c': 3}
>>> ser = pd.Series(data=d, index=['x', 'y', 'z'])
>>> ser
x   NaN
y   NaN
z   NaN
dtype: float64

Note that the Index is first build with the keys from the dictionary. After this the Series is reindexed with the given Index values, hence we get all NaN as a result.

Constructing Series from a list with copy=False.

>>> r = [1, 2]
>>> ser = pd.Series(r, copy=False)
>>> ser.iloc[0] = 999
>>> r
[1, 2]
>>> ser
0    999
1      2
dtype: int64

Due to input data type the Series has a copy of the original data even though copy=False, so the data is unchanged.

Constructing Series from a 1d ndarray with copy=False.

>>> r = np.array([1, 2])
>>> ser = pd.Series(r, copy=False)
>>> ser.iloc[0] = 999
>>> r
array([999,   2])
>>> ser
0    999
1      2
dtype: int64

Due to input data type the Series has a view on the original data, so the data is changed as well.

static _format(dataframe: pandas.core.frame.DataFrame) → pandas.core.frame.DataFrame[source]
asset_sheet() → pandas.core.frame.DataFrame[source]

generates a data sheet of “Asset” values

Returns:

pd.DataFrame: subset of the whole dataframe filtered by assets

asset_turnover(as_list: bool = False) → pandas.core.frame.DataFrame[source]

calculates asset turnover = revenue / assets

Args:
as_list (bool, optional): returns values as a list if True,

as a dataframe otherwise. Defaults to False.

Returns:

pd.DataFrame: the asset turnover

balance_sheet() → pandas.core.frame.DataFrame[source]
TODO:

generates the balance sheet

Returns:

pd.DataFrame: subset of the whole dataframe filtered by values on a balance sheet

book_value(as_list: bool = False) → pandas.core.frame.DataFrame[source]

calculates the book value = total assets - total liabilities

Args:
as_list (bool, optional): returns values as a list if True,

as a dataframe otherwise. Defaults to False.

Returns:

pd.DataFrame: the book values

cash_flow() → pandas.core.frame.DataFrame[source]
TODO:

generates the cash flow statement

Returns:

pd.DataFrame: subset of the whole dataframe filtered by values on a cash flow statement

cash_turnover(as_list: bool = False) → pandas.core.frame.DataFrame[source]

calculates cash turnover = revenue / cash and cash equivalents at carrying value

Args:
as_list (bool, optional): returns values as a list if True,

as a dataframe otherwise. Defaults to False.

Returns:

pd.DataFrame: the cash turnover

current_asset_turnover(as_list: bool = False) → pandas.core.frame.DataFrame[source]

calculates current asset turnover = revenue / current assets

Args:
as_list (bool, optional): returns values as a list if True,

as a dataframe otherwise. Defaults to False.

Returns:

pd.DataFrame: the current asset turnover

current_ratio(as_list: bool = False) → pandas.core.frame.DataFrame[source]

calculates the current ratio = current assets / current liabilities

Args:
as_list (bool, optional): returns values as a list if True,

as a dataframe otherwise. Defaults to False.

Returns:

pd.DataFrame: the current ratio values

debt_capitalization(as_list: bool = False) → pandas.core.frame.DataFrame[source]

calculates debt capitalization = liabilities / (liabilities + stockholder equity)

Args:
as_list (bool, optional): returns values as a list if True,

as a dataframe otherwise. Defaults to False.

Returns:

pd.DataFrame: the debt capitalization

debt_sheet() → pandas.core.frame.DataFrame[source]

generates a data sheet of “Debt” values

Returns:

pd.DataFrame: subset of the whole dataframe filtered by debts

debt_to_assets(as_list: bool = False) → pandas.core.frame.DataFrame[source]

calculates the debt-to-equity ratio = total liabilities / total assets

Args:
as_list (bool, optional): returns values as a list if True,

as a dataframe otherwise. Defaults to False.

Returns:

pd.DataFrame: the debt-to-assets ratio

debt_to_equity(as_list: bool = False) → pandas.core.frame.DataFrame[source]

calculates the debt-to-equity ratio = total liabilities / total stockholders equity

Args:
as_list (bool, optional): returns values as a list if True,

as a dataframe otherwise. Defaults to False.

Returns:

pd.DataFrame: the debt-to-equity ratio

ebit(as_list: bool = False) → pandas.core.frame.DataFrame[source]

calculates EBIT = Net Income + Taxes

Args:
as_list (bool, optional): returns values as a list if True,

as a dataframe otherwise. Defaults to False.

Returns:

pd.DataFrame: the EBIT

ebitda(as_list: bool = False) → pandas.core.frame.DataFrame[source]

calculates EBITDA = Net Income + Taxes + Depreciation + Amortization

Args:
as_list (bool, optional): returns values as a list if True,

as a dataframe otherwise. Defaults to False.

Returns:

pd.DataFrame: the EBITDA

effective_tax_rate(as_list: bool = False) → pandas.core.frame.DataFrame[source]

calculates effective tax rate = income tax / EBIT

Args:
as_list (bool, optional): returns values as a list if True,

as a dataframe otherwise. Defaults to False.

Returns:

pd.DataFrame: the effective tax rate

gross_margin(as_list: bool = False) → pandas.core.frame.DataFrame[source]

calculates gross margin

Args:
as_list (bool, optional): returns values as a list if True,

as a dataframe otherwise. Defaults to False.

Returns:

pd.DataFrame: the gross margin

inventory_turnover(as_list: bool = False) → pandas.core.frame.DataFrame[source]

calculates inventory tower = revenue / inventory net

Args:
as_list (bool, optional): returns values as a list if True,

as a dataframe otherwise. Defaults to False.

Returns:

pd.DataFrame: the inventory turnover

liability_sheet() → pandas.core.frame.DataFrame[source]

generates a data sheet of “Liability” values

Returns:

pd.DataFrame: subset of the whole dataframe filtered by liabilities

net_income(as_list: bool = False) → pandas.core.frame.DataFrame[source]

calculates net income

Args:
as_list (bool, optional): returns values as a list if True,

as a dataframe otherwise. Defaults to False.

Returns:

pd.DataFrame: the net income

net_working_capital(as_list: bool = False) → pandas.core.frame.DataFrame[source]

calculates net working capital = current assets - liabilities

Args:
as_list (bool, optional): returns values as a list if True,

as a dataframe otherwise. Defaults to False.

Returns:

pd.DataFrame: the effective tax rate

net_working_capital_per_share(as_list: bool = False) → pandas.core.frame.DataFrame[source]

calculates net working capital = current assets - liabilities

Args:
as_list (bool, optional): returns values as a list if True,

as a dataframe otherwise. Defaults to False.

Returns:

pd.DataFrame: the effective tax rate

quick_ratio(as_list: bool = False) → pandas.core.frame.DataFrame[source]

calculates the quick ratio = (current assets - inventory) / current liabilities

Args:
as_list (bool, optional): returns values as a list if True,

as a dataframe otherwise. Defaults to False.

Returns:

pd.DataFrame: the quick ratio values

receivables_turnover(as_list: bool = False) → pandas.core.frame.DataFrame[source]

calculates receivables turnover = revenue / account receivable

Args:
as_list (bool, optional): returns values as a list if True,

as a dataframe otherwise. Defaults to False.

Returns:

pd.DataFrame: the receivables turnover

return_on_assets(as_list: bool = False) → pandas.core.frame.DataFrame[source]

calculates ROA = net income / average total assets

Args:
as_list (bool, optional): returns values as a list if True,

as a dataframe otherwise. Defaults to False.

Returns:

pd.DataFrame: the ROA values

TODO:

make sure values are interpreted correctly for 10Q/10K distinction

return_on_equity(as_list: bool = False) → pandas.core.frame.DataFrame[source]

calculates ROE = net income / total stockholders equity

Args:
as_list (bool, optional): returns values as a list if True,

as a dataframe otherwise. Defaults to False.

Returns:

pd.DataFrame: the ROE values

TODO:

make sure values are interpreted correctly for 10Q/10K distinction

revenue(as_list: bool = False) → pandas.core.frame.DataFrame[source]

calculates revenue

Args:
as_list (bool, optional): returns values as a list if True,

as a dataframe otherwise. Defaults to False.

Returns:

pd.DataFrame: the revenue

search(regex: str, index: str = 'tag', axis: int = 0) → pandas.core.frame.DataFrame[source]

generates a data sheet based on a keyword regex

Args:

regex (str): the keyword regular expression index (str, optional): dataframe index to search along

(“tag”, “uom”, “fy”, “fp”, etc.). Defaults to “tag”.

axis (int, optional): the axis the index belongs to

(“tag”, “uom” on 0, “fy”, “fp” on 1). Defaults to 0.

Returns:

pd.DataFrame: subset of the whole dataframe filtered by the regex

class finpandas.dataframes.forms.Form10K(dataframe: pandas.core.frame.DataFrame)[source]

Bases: finpandas.dataframes.forms.Form

Abstract Data Type for the SEC Form 10-K

static _format(dataframe: pandas.core.frame.DataFrame) → pandas.core.frame.DataFrame[source]

adds a column designating which source column dataframe values came from

Args:

dataframe (pd.DataFrame): the raw content

Returns:

pd.DataFrame: the formatted content

class finpandas.dataframes.forms.Form10Q(dataframe: pandas.core.frame.DataFrame)[source]

Bases: finpandas.dataframes.forms.Form

Abstract Data Type for the SEC Form 10-Q

static _format(dataframe: pandas.core.frame.DataFrame) → pandas.core.frame.DataFrame[source]

group source content into 10Q format

Args:

dataframe (pd.DataFrame): the raw content

Returns:

pd.DataFrame: the formatted content

finpandas.dataframes.prices module

Abstract data types for historical pricing.

class finpandas.dataframes.prices.HistoricalPrices(dataframe: pandas.core.frame.DataFrame)[source]

Bases: pandas.core.frame.DataFrame

Abstract Data Type for historical prices. Subclass of pandas DataFrame.

property _constructor

Used when a manipulation result has the same dimensions as the original.

property _constructor_expanddim
property _constructor_sliced

One-dimensional ndarray with axis labels (including time series).

Labels need not be unique but must be a hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index. Statistical methods from ndarray have been overridden to automatically exclude missing data (currently represented as NaN).

Operations between Series (+, -, /, , *) align values based on their associated index values– they need not be the same length. The result index will be the sorted union of the two indexes.

dataarray-like, Iterable, dict, or scalar value

Contains data stored in Series. If data is a dict, argument order is maintained.

indexarray-like or Index (1d)

Values must be hashable and have the same length as data. Non-unique index values are allowed. Will default to RangeIndex (0, 1, 2, …, n) if not provided. If data is dict-like and index is None, then the keys in the data are used as the index. If the index is not None, the resulting Series is reindexed with the index values.

dtypestr, numpy.dtype, or ExtensionDtype, optional

Data type for the output Series. If not specified, this will be inferred from data. See the user guide for more usages.

namestr, optional

The name to give to the Series.

copybool, default False

Copy input data. Only affects Series or 1d ndarray input. See examples.

Constructing Series from a dictionary with an Index specified

>>> d = {'a': 1, 'b': 2, 'c': 3}
>>> ser = pd.Series(data=d, index=['a', 'b', 'c'])
>>> ser
a   1
b   2
c   3
dtype: int64

The keys of the dictionary match with the Index values, hence the Index values have no effect.

>>> d = {'a': 1, 'b': 2, 'c': 3}
>>> ser = pd.Series(data=d, index=['x', 'y', 'z'])
>>> ser
x   NaN
y   NaN
z   NaN
dtype: float64

Note that the Index is first build with the keys from the dictionary. After this the Series is reindexed with the given Index values, hence we get all NaN as a result.

Constructing Series from a list with copy=False.

>>> r = [1, 2]
>>> ser = pd.Series(r, copy=False)
>>> ser.iloc[0] = 999
>>> r
[1, 2]
>>> ser
0    999
1      2
dtype: int64

Due to input data type the Series has a copy of the original data even though copy=False, so the data is unchanged.

Constructing Series from a 1d ndarray with copy=False.

>>> r = np.array([1, 2])
>>> ser = pd.Series(r, copy=False)
>>> ser.iloc[0] = 999
>>> r
array([999,   2])
>>> ser
0    999
1      2
dtype: int64

Due to input data type the Series has a view on the original data, so the data is changed as well.

static _format(dataframe: pandas.core.frame.DataFrame) → pandas.core.frame.DataFrame[source]
class finpandas.dataframes.prices.HistoricalStockPrices(dataframe: pandas.core.frame.DataFrame)[source]

Bases: finpandas.dataframes.prices.HistoricalPrices

Abstract Data Type for historical stock prices

static _format(dataframe: pandas.core.frame.DataFrame) → pandas.core.frame.DataFrame[source]

group source content into a usable format

Args:

dataframe (pd.DataFrame): the raw content

Returns:

pd.DataFrame: the formatted content

Module contents

modified dataframe classes