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


Python pandas.RangeIndex方法代碼示例

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


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

示例1: getStockHdStatistics

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import RangeIndex [as 別名]
def getStockHdStatistics(cls, code, browser, retryCount=3):
        """ 抓取持股統計

        :param code: 股票代碼
        :param browser: webdriver瀏覽器
        :return:
        """
        url = 'http://data.eastmoney.com/hsgtcg/StockHdStatistics.aspx?stock={}'.format(code)
        for i in range(retryCount):
            df = cls.scrap(url, browser)
            if len(df) > 0:
                # 修複持股數量
                df['hvol'] = df['hvol'].apply(lambda x: HSGTCG.hz2Num(x)).astype(float)
                df['hamount'] = df['hamount'].apply(lambda x: HSGTCG.hz2Num(x)).astype(float)
                df['close'] = df['close'].astype(float)
                df['tradedate'] = df['tradedate'].apply(lambda x: convertToDate(x)).astype(datetime.date)
                df = df[df['tradedate'].apply(lambda x: Stocktradedate.if_tradeday(x))]  # 刪除不是交易日的數據。這是東方財富網頁版的bug
                df.index = pd.RangeIndex(len(df.index))
                break
            else:
                pass

        return df 
開發者ID:pchaos,項目名稱:wanggeService,代碼行數:25,代碼來源:hsgtcg.py

示例2: test_constructor_name

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import RangeIndex [as 別名]
def test_constructor_name(self):
        # GH12288
        orig = RangeIndex(10)
        orig.name = 'original'

        copy = RangeIndex(orig)
        copy.name = 'copy'

        assert orig.name == 'original'
        assert copy.name == 'copy'

        new = Index(copy)
        assert new.name == 'copy'

        new.name = 'new'
        assert orig.name == 'original'
        assert copy.name == 'copy'
        assert new.name == 'new' 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:20,代碼來源:test_range.py

示例3: test_delete

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import RangeIndex [as 別名]
def test_delete(self):

        idx = RangeIndex(5, name='Foo')
        expected = idx[1:].astype(int)
        result = idx.delete(0)
        tm.assert_index_equal(result, expected)
        assert result.name == expected.name

        expected = idx[:-1].astype(int)
        result = idx.delete(-1)
        tm.assert_index_equal(result, expected)
        assert result.name == expected.name

        with pytest.raises((IndexError, ValueError)):
            # either depending on numpy version
            result = idx.delete(len(idx)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:18,代碼來源:test_range.py

示例4: test_explicit_conversions

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import RangeIndex [as 別名]
def test_explicit_conversions(self):

        # GH 8608
        # add/sub are overridden explicitly for Float/Int Index
        idx = RangeIndex(5)

        # float conversions
        arr = np.arange(5, dtype='int64') * 3.2
        expected = Float64Index(arr)
        fidx = idx * 3.2
        tm.assert_index_equal(fidx, expected)
        fidx = 3.2 * idx
        tm.assert_index_equal(fidx, expected)

        # interops with numpy arrays
        expected = Float64Index(arr)
        a = np.zeros(5, dtype='float64')
        result = fidx - a
        tm.assert_index_equal(result, expected)

        expected = Float64Index(-arr)
        a = np.zeros(5, dtype='float64')
        result = a - fidx
        tm.assert_index_equal(result, expected) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:26,代碼來源:test_range.py

示例5: test_min_fitting_element

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import RangeIndex [as 別名]
def test_min_fitting_element(self):
        result = RangeIndex(0, 20, 2)._min_fitting_element(1)
        assert 2 == result

        result = RangeIndex(1, 6)._min_fitting_element(1)
        assert 1 == result

        result = RangeIndex(18, -2, -2)._min_fitting_element(1)
        assert 2 == result

        result = RangeIndex(5, 0, -1)._min_fitting_element(1)
        assert 1 == result

        big_num = 500000000000000000000000

        result = RangeIndex(5, big_num * 2, 1)._min_fitting_element(big_num)
        assert big_num == result 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:19,代碼來源:test_range.py

示例6: test_max_fitting_element

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import RangeIndex [as 別名]
def test_max_fitting_element(self):
        result = RangeIndex(0, 20, 2)._max_fitting_element(17)
        assert 16 == result

        result = RangeIndex(1, 6)._max_fitting_element(4)
        assert 4 == result

        result = RangeIndex(18, -2, -2)._max_fitting_element(17)
        assert 16 == result

        result = RangeIndex(5, 0, -1)._max_fitting_element(4)
        assert 4 == result

        big_num = 500000000000000000000000

        result = RangeIndex(5, big_num * 2, 1)._max_fitting_element(big_num)
        assert big_num == result 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:19,代碼來源:test_range.py

示例7: test_duplicated

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import RangeIndex [as 別名]
def test_duplicated(self, indices, keep):
        if not len(indices) or isinstance(indices, (MultiIndex, RangeIndex)):
            # MultiIndex tested separately in:
            # tests/indexes/multi/test_unique_and_duplicates
            pytest.skip('Skip check for empty Index, MultiIndex, RangeIndex')

        holder = type(indices)

        idx = holder(indices)
        if idx.has_duplicates:
            # We are testing the duplicated-method here, so we need to know
            # exactly which indices are duplicate and how (for the result).
            # This is not possible if "idx" has duplicates already, which we
            # therefore remove. This is seemingly circular, as drop_duplicates
            # invokes duplicated, but in the end, it all works out because we
            # cross-check with Series.duplicated, which is tested separately.
            idx = idx.drop_duplicates()

        n, k = len(idx), 10
        duplicated_selection = np.random.choice(n, k * n)
        expected = pd.Series(duplicated_selection).duplicated(keep=keep).values
        idx = holder(idx.values[duplicated_selection])

        result = idx.duplicated(keep=keep)
        tm.assert_numpy_array_equal(result, expected) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:27,代碼來源:test_common.py

示例8: test_numpy_argsort

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import RangeIndex [as 別名]
def test_numpy_argsort(idx):
    result = np.argsort(idx)
    expected = idx.argsort()
    tm.assert_numpy_array_equal(result, expected)

    # these are the only two types that perform
    # pandas compatibility input validation - the
    # rest already perform separate (or no) such
    # validation via their 'values' attribute as
    # defined in pandas.core.indexes/base.py - they
    # cannot be changed at the moment due to
    # backwards compatibility concerns
    if isinstance(type(idx), (CategoricalIndex, RangeIndex)):
        msg = "the 'axis' parameter is not supported"
        with pytest.raises(ValueError, match=msg):
            np.argsort(idx, axis=1)

        msg = "the 'kind' parameter is not supported"
        with pytest.raises(ValueError, match=msg):
            np.argsort(idx, kind='mergesort')

        msg = "the 'order' parameter is not supported"
        with pytest.raises(ValueError, match=msg):
            np.argsort(idx, order=('a', 'b')) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:26,代碼來源:test_sorting.py

示例9: setattributeindex

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import RangeIndex [as 別名]
def setattributeindex(self, instance, value):
        bus_name = instance.bus.index
        instance.branch['F_BUS'] = instance.branch['F_BUS'].apply(lambda x: value[bus_name.get_loc(x)])
        instance.branch['T_BUS'] = instance.branch['T_BUS'].apply(lambda x: value[bus_name.get_loc(x)])
        instance.gen['GEN_BUS'] = instance.gen['GEN_BUS'].apply(lambda x: value[bus_name.get_loc(x)])

        try:
            instance.load.columns = [v for b, v in zip(instance.bus_name.isin(instance.load.columns), value) if b == True]
        except ValueError:
            instance.load.columns = value
        except AttributeError:
            instance.load = pd.DataFrame(0, index=range(0, 1), columns=value, dtype='float')

        instance.bus.index = value

        if isinstance(instance.bus_name, pd.RangeIndex) or isinstance(instance.bus_name, pd.Int64Index):
            logger.debug('Forcing string types for all bus names')
            instance.bus_name = ['Bus{}'.format(b) for b in instance.bus_name] 
開發者ID:power-system-simulation-toolbox,項目名稱:psst,代碼行數:20,代碼來源:descriptors.py

示例10: call

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import RangeIndex [as 別名]
def call(cls, op, inp):
        method_kwargs = op.method_kwargs
        if method_kwargs.get('expand', False) is False:
            return super().call(op, inp)
        n = method_kwargs.get('n', -1)
        # does not support if expand and n == -1
        if n == -1:  # pragma: no cover
            raise NotImplementedError('`n` needs to be specified when expand=True')

        op.output_types = [OutputType.dataframe]
        columns = pd.RangeIndex(n + 1)
        columns_value = parse_index(columns, store_data=True)
        dtypes = pd.Series([inp.dtype] * len(columns), index=columns)
        return op.new_dataframe([inp], shape=(inp.shape[0], len(columns)),
                                dtypes=dtypes, columns_value=columns_value,
                                index_value=inp.index_value) 
開發者ID:mars-project,項目名稱:mars,代碼行數:18,代碼來源:string_.py

示例11: __call__

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import RangeIndex [as 別名]
def __call__(self, inp, inplace=False):
        self._output_types = inp.op.output_types
        params = inp.params
        if self._ignore_index:
            params['index_value'] = parse_index(pd.RangeIndex(-1))
        else:
            params['index_value'] = gen_unknown_index_value(
                params['index_value'], self._keep, self._subset, type(self).__name__)
        shape_list = list(params['shape'])
        shape_list[0] = np.nan
        params['shape'] = tuple(shape_list)

        ret = self.new_tileable([inp], kws=[params])
        if inplace:
            inp.data = ret.data
        return ret 
開發者ID:mars-project,項目名稱:mars,代碼行數:18,代碼來源:drop_duplicates.py

示例12: _infer_df_func_returns

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import RangeIndex [as 別名]
def _infer_df_func_returns(self, in_dtypes, dtypes):
        if self.output_types[0] == OutputType.dataframe:
            empty_df = build_empty_df(in_dtypes, index=pd.RangeIndex(2))
            with np.errstate(all='ignore'):
                if self.call_agg:
                    infer_df = empty_df.agg(self._func, axis=self._axis, *self.args, **self.kwds)
                else:
                    infer_df = empty_df.transform(self._func, axis=self._axis, *self.args, **self.kwds)
        else:
            empty_df = build_empty_series(in_dtypes[1], index=pd.RangeIndex(2), name=in_dtypes[0])
            with np.errstate(all='ignore'):
                if self.call_agg:
                    infer_df = empty_df.agg(self._func, args=self.args, **self.kwds)
                else:
                    infer_df = empty_df.transform(self._func, convert_dtype=self.convert_dtype,
                                                  args=self.args, **self.kwds)

        if isinstance(infer_df, pd.DataFrame):
            new_dtypes = dtypes or infer_df.dtypes
            self.output_types = [OutputType.dataframe]
        else:
            new_dtypes = dtypes or (infer_df.name, infer_df.dtype)
            self.output_types = [OutputType.series]

        return new_dtypes 
開發者ID:mars-project,項目名稱:mars,代碼行數:27,代碼來源:transform.py

示例13: tile

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import RangeIndex [as 別名]
def tile(cls, op: 'DataFrameMelt'):
        inp = op.inputs[0]
        out = op.outputs[0]

        inp = inp.rechunk({1: (inp.shape[1],)})._inplace_tile()

        chunks = []
        for c in inp.chunks:
            new_op = op.copy().reset_key()
            chunks.append(new_op.new_chunk(
                [c], index=c.index,  shape=(np.nan, out.shape[1]), dtypes=out.dtypes,
                index_value=parse_index(pd.RangeIndex(-1), c.key, c.index_value.key),
                columns_value=out.columns_value))

        chunks = standardize_range_index(chunks)
        new_op = op.copy().reset_key()
        return new_op.new_tileables(
            [inp], chunks=chunks, nsplits=((np.nan,) * inp.chunk_shape[0], (out.shape[1],)), **out.params) 
開發者ID:mars-project,項目名稱:mars,代碼行數:20,代碼來源:melt.py

示例14: _call_dataframe

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import RangeIndex [as 別名]
def _call_dataframe(self, a):
        if self.drop:
            shape = a.shape
            columns_value = a.columns_value
            dtypes = a.dtypes
            range_value = -1 if np.isnan(a.shape[0]) else a.shape[0]
            index_value = parse_index(pd.RangeIndex(range_value))
        else:
            empty_df = build_empty_df(a.dtypes)
            empty_df.index = a.index_value.to_pandas()[:0]
            empty_df = empty_df.reset_index(level=self.level, col_level=self.col_level, col_fill=self.col_fill)
            shape = (a.shape[0], len(empty_df.columns))
            columns_value = parse_index(empty_df.columns, store_data=True)
            dtypes = empty_df.dtypes
            index_value = self._get_out_index(empty_df, shape)
        return self.new_dataframe([a], shape=shape, columns_value=columns_value,
                                  index_value=index_value, dtypes=dtypes) 
開發者ID:mars-project,項目名稱:mars,代碼行數:19,代碼來源:reset_index.py

示例15: testFromRecordsExecution

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import RangeIndex [as 別名]
def testFromRecordsExecution(self):
        dtype = np.dtype([('x', 'int'), ('y', 'double'), ('z', '<U16')])

        ndarr = np.ones((10,), dtype=dtype)
        pdf_expected = pd.DataFrame.from_records(ndarr, index=pd.RangeIndex(10))

        # from structured array of mars
        tensor = mt.ones((10,), dtype=dtype, chunk_size=3)
        df1 = from_records(tensor)
        df1_result = self.executor.execute_dataframe(df1, concat=True)[0]
        pd.testing.assert_frame_equal(df1_result, pdf_expected)

        # from structured array of numpy
        df2 = from_records(ndarr)
        df2_result = self.executor.execute_dataframe(df2, concat=True)[0]
        pd.testing.assert_frame_equal(df2_result, pdf_expected) 
開發者ID:mars-project,項目名稱:mars,代碼行數:18,代碼來源:test_datasource_execution.py


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