當前位置: 首頁>>代碼示例>>Python>>正文


Python pandas.DataFrames方法代碼示例

本文整理匯總了Python中pandas.DataFrames方法的典型用法代碼示例。如果您正苦於以下問題:Python pandas.DataFrames方法的具體用法?Python pandas.DataFrames怎麽用?Python pandas.DataFrames使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pandas的用法示例。


在下文中一共展示了pandas.DataFrames方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import DataFrames [as 別名]
def __init__(self, corr_list, column_names, fit_dates):
        """
        Returns a time series of forecasts for a particular instrument

        :param instrument_code:
        :type str:

        :param rule_variation_list:
        :type list: list of str to get forecasts for, if None uses get_trading_rule_list

        :returns: TxN pd.DataFrames; columns rule_variation_name

        """

        setattr(self, "corr_list", corr_list)
        setattr(self, "columns", column_names)
        setattr(self, "fit_dates", fit_dates) 
開發者ID:robcarver17,項目名稱:pysystemtrade,代碼行數:19,代碼來源:correlations.py

示例2: get_capped_forecast

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import DataFrames [as 別名]
def get_capped_forecast(self, instrument_code, rule_variation_name):
        """
        Get the capped forecast from the previous module


        KEY INPUT

        :param instrument_code:
        :type str:

        :param rule_variation_name:
        :type str: name of the trading rule variation

        :returns: Tx1 pd.DataFrames

        """
        return self.parent.forecastScaleCap.get_capped_forecast(
            instrument_code, rule_variation_name) 
開發者ID:robcarver17,項目名稱:pysystemtrade,代碼行數:20,代碼來源:accounts_inputs.py

示例3: get_forecast_weights

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import DataFrames [as 別名]
def get_forecast_weights(self, instrument_code):
        """
        Get the capped forecast from the previous module

        KEY INPUT

        :param instrument_code:
        :type str:

        :param rule_variation_name:
        :type str: name of the trading rule variation

        :returns: dict of Tx1 pd.DataFrames

        """
        return self.parent.combForecast.get_forecast_weights(instrument_code) 
開發者ID:robcarver17,項目名稱:pysystemtrade,代碼行數:18,代碼來源:accounts_inputs.py

示例4: get_aligned_forecast

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import DataFrames [as 別名]
def get_aligned_forecast(self, instrument_code, rule_variation_name):
        """
        Get the capped forecast aligned to daily prices


        KEY INPUT

        :param instrument_code:
        :type str:

        :param rule_variation_name:
        :type str: name of the trading rule variation

        :returns: Tx1 pd.DataFrames

        """
        price = self.get_daily_price(instrument_code)
        forecast = self.get_capped_forecast(instrument_code,
                                            rule_variation_name)

        forecast = forecast.reindex(price.index).ffill()

        return forecast 
開發者ID:robcarver17,項目名稱:pysystemtrade,代碼行數:25,代碼來源:accounts_inputs.py

示例5: get_daily_returns_volatility

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import DataFrames [as 別名]
def get_daily_returns_volatility(self, instrument_code):
        """
        Get the daily return (not %) volatility from previous stage, or calculate

        KEY INPUT

        :param instrument_code:
        :type str:

        :returns: Tx1 pd.DataFrames

        """

        system = self.parent
        if hasattr(system, "rawdata"):
            returns_vol = system.rawdata.daily_returns_volatility(
                instrument_code)
        else:
            price = self.get_daily_price(instrument_code)
            returns_vol = robust_vol_calc(price.diff())

        return returns_vol 
開發者ID:robcarver17,項目名稱:pysystemtrade,代碼行數:24,代碼來源:accounts_inputs.py

示例6: is_same_as

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import DataFrames [as 別名]
def is_same_as(df, df_to_compare, **kwargs):
    """Asserts that two pd.DataFrames are equal.

    Args:
        df (pd.DataFrame): Any pd.DataFrame.
        df_to_compare (pd.DataFrame): A second pd.DataFrame.
        **kwargs (dict): Keyword arguments passed through to pandas' ``assert_frame_equal``.

    Returns:
        Original `df`.

    """
    try:
        tm.assert_frame_equal(df, df_to_compare, **kwargs)
    except AssertionError as exc:
        raise AssertionError("DataFrames are not equal") from exc
    return df 
開發者ID:ZaxR,項目名稱:bulwark,代碼行數:19,代碼來源:checks.py

示例7: _check_params

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import DataFrames [as 別名]
def _check_params(params):
    """Check params has a unique index and contains no columns to be created internally.

    Args:
        params (pd.DataFrame or list of pd.DataFrames): See :ref:`params`.

    Raises:
        AssertionError: The index contains duplicates.
        ValueError: The DataFrame contains internal columns.

    """
    assert (
        not params.index.duplicated().any()
    ), "No duplicates allowed in the index of params."

    invalid_names = [
        "_fixed",
        "_fixed_value",
        "_is_fixed_to_value",
        "_is_fixed_to_other",
    ]
    invalid_present_columns = []
    for col in params.columns:
        if col in invalid_names or col.startswith("_internal"):
            invalid_present_columns.append(col)

    if len(invalid_present_columns) > 0:
        msg = (
            "Column names starting with '_internal' and as well as any other of the "
            f"following columns are not allowed in params:\n{invalid_names}."
            f"This is violated for:\n{invalid_present_columns}."
        )
        raise ValueError(msg) 
開發者ID:OpenSourceEconomics,項目名稱:estimagic,代碼行數:35,代碼來源:transform_problem.py

示例8: read_data

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import DataFrames [as 別名]
def read_data(data_dir, dates):
    """Builds dataframe for model and func benchmarks Assumes directory is structured as
     DATA_PATH
        |_2020-02-20
            |_func_benchmarks.csv
            |_model_benchmarks.csv

    Args:
        data_dir (pathlib.path): path containing month subdirectories
        dates (list of str): containing dates / subdirectories available

    Returns: tuple of pd.DataFrames containing func and model benchmarks with dates
    """
    func_df, model_df = None, None

    for date in dates:
        path = os.path.join(data_dir, date)
        tmp_func_df = pd.read_csv(os.path.join(path, "func_benchmarks.csv"))
        tmp_model_df = pd.read_csv(os.path.join(path, "model_benchmarks.csv"))
        tmp_func_df["date"], tmp_model_df["date"] = date, date
        if func_df is None:
            func_df = tmp_func_df.copy()
            model_df = tmp_model_df.copy()
        else:
            func_df = func_df.append(tmp_func_df)
            model_df = model_df.append(tmp_model_df)

    func_df = compute_runtime_gap(func_df)
    func_df = add_error_bars(func_df)
    return func_df, model_df 
開發者ID:facebookresearch,項目名稱:CrypTen,代碼行數:32,代碼來源:load_data.py

示例9: apply_viewdf_layout

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import DataFrames [as 別名]
def apply_viewdf_layout(df, x, y):
    '''
    Takes a pd.DataFrames and applies Quantipy's Question/Values
    layout to it by creating a multiindex on both axes.

    Parameters
    ----------
    df : pd.DataFrame

    x, y : str
        Variable names from the processed case data input,
        i.e. the link definition.

    Returns
    -------
    df : pd.Dataframe (multiindexed)
    '''
    axis_labels = ['Question', 'Values']
    df.index = pd.MultiIndex.from_product([[x], df.index], names=axis_labels)
    if y is None:
        df.columns = pd.MultiIndex.from_product([[x], df.columns], names=axis_labels)
    elif y == '@':
        df.columns = pd.MultiIndex.from_product([[x], '@'], names=axis_labels)
    else:
        df.columns = pd.MultiIndex.from_product([[y], df.columns], names=axis_labels)

    return df

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
開發者ID:Quantipy,項目名稱:quantipy,代碼行數:31,代碼來源:functions.py

示例10: set_qp_multiindex

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import DataFrames [as 別名]
def set_qp_multiindex(df, x, y):
    '''
    Takes a pd.DataFrames and applies Quantipy's Question/Values
    layout to it by creating a multiindex on both axes.

    Parameters
    ----------
    df : pd.DataFrame

    x, y : str
        Variable names from the processed case data input,
        i.e. the link definition.

    Returns
    -------
    df : pd.Dataframe (Quantipy convention, multiindexed)
    '''
    axis_labels = ['Question', 'Values']
    df.index = pd.MultiIndex.from_product([[x], df.index], names=axis_labels)
    if y is None:
        df.columns = pd.MultiIndex.from_product([[x], df.columns], names=axis_labels)
    elif y == '@':
        df.columns = pd.MultiIndex.from_product([[x], '@'], names=axis_labels)
    else:
        df.columns = pd.MultiIndex.from_product([[y], df.columns], names=axis_labels)

    return df 
開發者ID:Quantipy,項目名稱:quantipy,代碼行數:29,代碼來源:functions.py

示例11: set_qp_multiindex

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import DataFrames [as 別名]
def set_qp_multiindex(df, x, y):
    '''
    Takes a pd.DataFrames and applies Quantipy's Question/Values
    layout to it by creating a multiindex on both axes.

    Parameters
    ----------
    df : pd.DataFrame

    x, y : str
        Variable names from the processed case data input,
        i.e. the link definition.

    Returns
    -------
    df : pd.Dataframe (Quantipy convention, multiindexed)
    '''
    axis_labels = ['Question', 'Values']
    df.index = pd.MultiIndex.from_product([[x], df.index], names=axis_labels)
    if y is None:
        df.columns = pd.MultiIndex.from_product([[x], df.columns], names=axis_labels)
    elif y == '@':
        df.columns = pd.MultiIndex.from_product([[x], df.columns], names=axis_labels)
    else:
        df.columns = pd.MultiIndex.from_product([[y], df.columns], names=axis_labels)

    return df 
開發者ID:Quantipy,項目名稱:quantipy,代碼行數:29,代碼來源:struct.py

示例12: get_forecast_diversification_multiplier

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import DataFrames [as 別名]
def get_forecast_diversification_multiplier(self, instrument_code):
        """
        Get the f.d.m from the previous module

        KEY INPUT

        :param instrument_code:
        :type str:

        :returns: dict of Tx1 pd.DataFrames

        """
        return self.parent.combForecast.get_forecast_diversification_multiplier(
            instrument_code) 
開發者ID:robcarver17,項目名稱:pysystemtrade,代碼行數:16,代碼來源:accounts_inputs.py

示例13: get_daily_price

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import DataFrames [as 別名]
def get_daily_price(self, instrument_code):
        """
        Get the instrument price from rawdata

        Cached as data isn't cached

        :param instrument_code:
        :type str:

        :returns: Tx1 pd.DataFrames

        """
        return self.parent.data.daily_prices(instrument_code) 
開發者ID:robcarver17,項目名稱:pysystemtrade,代碼行數:15,代碼來源:accounts_inputs.py

示例14: get_capped_forecast

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import DataFrames [as 別名]
def get_capped_forecast(self, instrument_code, rule_variation_name):
        """
        Get the capped forecast from the previous module

        KEY INPUT

        :param instrument_code:
        :type str:

        :param rule_variation_name:
        :type str: name of the trading rule variation

        :returns: dict of Tx1 pd.DataFrames; keynames rule_variation_name

        >>> from systems.tests.testdata import get_test_object_futures_with_rules_and_capping
        >>> from systems.basesystem import System
        >>> (fcs, rules, rawdata, data, config)=get_test_object_futures_with_rules_and_capping()
        >>> system=System([rawdata, rules, fcs, ForecastCombineFixed()], data, config)
        >>> system.combForecast.get_capped_forecast("EDOLLAR","ewmac8").tail(2)
                      ewmac8
        2015-12-10 -0.190583
        2015-12-11  0.871231
        """

        return self.parent.forecastScaleCap.get_capped_forecast(
            instrument_code, rule_variation_name) 
開發者ID:robcarver17,項目名稱:pysystemtrade,代碼行數:28,代碼來源:forecast_combine.py

示例15: get_all_forecasts

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import DataFrames [as 別名]
def get_all_forecasts(self, instrument_code, rule_variation_list=None):
        """
        Returns a data frame of forecasts for a particular instrument

        KEY INPUT

        :param instrument_code:
        :type str:

        :param rule_variation_list:
        :type list: list of str to get forecasts for, if None uses get_trading_rule_list

        :returns: TxN pd.DataFrames; columns rule_variation_name

        >>> from systems.tests.testdata import get_test_object_futures_with_rules_and_capping
        >>> from systems.basesystem import System
        >>> (fcs, rules, rawdata, data, config)=get_test_object_futures_with_rules_and_capping()
        >>> system1=System([rawdata, rules, fcs, ForecastCombineFixed()], data, config)
        >>> system1.combForecast.get_all_forecasts("EDOLLAR",["ewmac8"]).tail(2)
                      ewmac8
        2015-12-10 -0.190583
        2015-12-11  0.871231
        >>>
        >>> system2=System([rawdata, rules, fcs, ForecastCombineFixed()], data, config)
        >>> system2.combForecast.get_all_forecasts("EDOLLAR").tail(2)
                     ewmac16    ewmac8
        2015-12-10  3.134462 -0.190583
        2015-12-11  3.606243  0.871231
        """

        if rule_variation_list is None:
            rule_variation_list = self.get_trading_rule_list(
                instrument_code)

        forecasts = self.get_forecasts_given_rule_list(instrument_code, rule_variation_list)

        return forecasts 
開發者ID:robcarver17,項目名稱:pysystemtrade,代碼行數:39,代碼來源:forecast_combine.py


注:本文中的pandas.DataFrames方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。