Mamajek_Table.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:gullikson-scripts 作者: kgullikson88 项目源码 文件源码
def get_interpolator(self, xcolumn, ycolumn, extrap='nearest'):
        """
        Get an interpolator instance between the two columns

        Parameters:
        ===========
        - xcolumn:    string
                      The name of the x column to interpolate between

        - ycolumn:    string
                      The name of the value you want to interpolate

        - extrap:     string
                      How to treat extrapolation. Options are:
                          1. 'nearest': Default behavior. It will return the nearest match
                             to the given 'x' value
                          2. 'extrapolate': Extrapolate the spline. This is probably only
                             safe for very small extrapolations

        Returns:
        ========
        A callable interpolator.
        """
        # Make sure the column names are correct
        assert xcolumn in self.mam_df.keys() and ycolumn in self.mam_df.keys()

        # Sort the dataframe by the x column, and drop any duplicates or nans it might have
        sorted_df = self.mam_df.sort_values(by=xcolumn).dropna(subset=[xcolumn, ycolumn], how='any').drop_duplicates(xcolumn)

        # Make an interpolator
        ext_value = {'nearest': 3, 'extrapolate': 0}
        fcn = spline(sorted_df[xcolumn].values, sorted_df[ycolumn].values, ext=ext_value[extrap])
        return fcn
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号