本文整理匯總了Python中pandas.util.testing.K屬性的典型用法代碼示例。如果您正苦於以下問題:Python testing.K屬性的具體用法?Python testing.K怎麽用?Python testing.K使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類pandas.util.testing
的用法示例。
在下文中一共展示了testing.K屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create_random_sample_set
# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import K [as 別名]
def create_random_sample_set(n_samples, time_shift='120m', randomize_times=False, freq='60T'):
# Create artificial data
tm.K = 3
tm.N = n_samples
# Random data frame with an hourly index
test_df = tm.makeTimeDataFrame(freq=freq)
# Turn the index into a column labeled 'index'
test_df = test_df.reset_index()
if randomize_times:
tm.K = 1
# Subtract and adds random time deltas to the index column, to create the prediction and evaluation times
rand_fact = tm.makeDataFrame().reset_index(drop=True).squeeze().iloc[:len(test_df)].abs()
test_df['index'] = test_df['index'].subtract(rand_fact.apply(lambda x: x * pd.Timedelta(time_shift)))
rand_fact = tm.makeDataFrame().reset_index(drop=True).squeeze().iloc[:len(test_df)].abs()
test_df['index2'] = test_df['index'].add(rand_fact.apply(lambda x: x * pd.Timedelta(time_shift)))
else:
test_df['index2'] = test_df['index'].apply(lambda x: x + pd.Timedelta(time_shift))
# Sort the data frame by prediction time
test_df = test_df.sort_values('index')
X = test_df[['A', 'B', 'C']]
pred_times = test_df['index']
exit_times = test_df['index2']
return X, pred_times, exit_times
示例2: test_panel_join_many
# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import K [as 別名]
def test_panel_join_many(self):
with catch_warnings(record=True):
tm.K = 10
panel = tm.makePanel()
tm.K = 4
panels = [panel.iloc[:2], panel.iloc[2:6], panel.iloc[6:]]
joined = panels[0].join(panels[1:])
tm.assert_panel_equal(joined, panel)
panels = [panel.iloc[:2, :-5],
panel.iloc[2:6, 2:],
panel.iloc[6:, 5:-7]]
data_dict = {}
for p in panels:
data_dict.update(p.iteritems())
joined = panels[0].join(panels[1:], how='inner')
expected = pd.Panel.from_dict(data_dict, intersect=True)
tm.assert_panel_equal(joined, expected)
joined = panels[0].join(panels[1:], how='outer')
expected = pd.Panel.from_dict(data_dict, intersect=False)
tm.assert_panel_equal(joined, expected)
# edge cases
msg = "Suffixes not supported when passing multiple panels"
with pytest.raises(ValueError, match=msg):
panels[0].join(panels[1:], how='outer', lsuffix='foo',
rsuffix='bar')
msg = "Right join not supported with multiple panels"
with pytest.raises(ValueError, match=msg):
panels[0].join(panels[1:], how='right')
示例3: test_panel_join_many
# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import K [as 別名]
def test_panel_join_many(self):
with catch_warnings(record=True):
tm.K = 10
panel = tm.makePanel()
tm.K = 4
panels = [panel.iloc[:2], panel.iloc[2:6], panel.iloc[6:]]
joined = panels[0].join(panels[1:])
tm.assert_panel_equal(joined, panel)
panels = [panel.iloc[:2, :-5],
panel.iloc[2:6, 2:],
panel.iloc[6:, 5:-7]]
data_dict = {}
for p in panels:
data_dict.update(p.iteritems())
joined = panels[0].join(panels[1:], how='inner')
expected = pd.Panel.from_dict(data_dict, intersect=True)
tm.assert_panel_equal(joined, expected)
joined = panels[0].join(panels[1:], how='outer')
expected = pd.Panel.from_dict(data_dict, intersect=False)
tm.assert_panel_equal(joined, expected)
# edge cases
pytest.raises(ValueError, panels[0].join, panels[1:],
how='outer', lsuffix='foo', rsuffix='bar')
pytest.raises(ValueError, panels[0].join, panels[1:],
how='right')
示例4: test_panel_join_many
# 需要導入模塊: from pandas.util import testing [as 別名]
# 或者: from pandas.util.testing import K [as 別名]
def test_panel_join_many(self):
tm.K = 10
panel = tm.makePanel()
tm.K = 4
panels = [panel.ix[:2], panel.ix[2:6], panel.ix[6:]]
joined = panels[0].join(panels[1:])
tm.assert_panel_equal(joined, panel)
panels = [panel.ix[:2, :-5], panel.ix[2:6, 2:], panel.ix[6:, 5:-7]]
data_dict = {}
for p in panels:
data_dict.update(compat.iteritems(p))
joined = panels[0].join(panels[1:], how='inner')
expected = Panel.from_dict(data_dict, intersect=True)
tm.assert_panel_equal(joined, expected)
joined = panels[0].join(panels[1:], how='outer')
expected = Panel.from_dict(data_dict, intersect=False)
tm.assert_panel_equal(joined, expected)
# edge cases
self.assertRaises(ValueError, panels[0].join, panels[1:],
how='outer', lsuffix='foo', rsuffix='bar')
self.assertRaises(ValueError, panels[0].join, panels[1:],
how='right')