dataframe.py 文件源码

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

项目:raccoon 作者: rsheftel 项目源码 文件源码
def get_location(self, location, columns=None, as_dict=False, index=True):
        """
        For an index location and list of columns return a DataFrame of the values. This is optimized for speed because
        it does not need to lookup the index location with a search. Also can accept relative indexing from the end of
        the DataFrame in standard python notation [-3, -2, -1]

        :param location: index location in standard python form of positive or negative number
        :param columns: list of columns, or None to include all columns
        :param as_dict: if True then return a dictionary
        :param index: if True then include the index in the dictionary if as_dict=True
        :return: DataFrame or dictionary
        """
        if columns is None:
            columns = self._columns
        elif all([isinstance(i, bool) for i in columns]):
            if len(columns) != len(self._columns):
                raise ValueError('boolean column list must be same size of existing columns')
            columns = list(compress(self._columns, columns))
        data = dict()
        for column in columns:
            c = self._columns.index(column)
            data[column] = self._data[c][location]
        index_value = self._index[location]
        if as_dict:
            if index:
                data[self._index_name] = index_value
            return data
        else:
            data = {k: [data[k]] for k in data}  # this makes the dict items lists
            return DataFrame(data=data, index=[index_value], columns=columns, index_name=self._index_name,
                             sort=self._sort)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号