本文整理汇总了Python中pandas.sparse.api.SparseDataFrame.corr方法的典型用法代码示例。如果您正苦于以下问题:Python SparseDataFrame.corr方法的具体用法?Python SparseDataFrame.corr怎么用?Python SparseDataFrame.corr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.sparse.api.SparseDataFrame
的用法示例。
在下文中一共展示了SparseDataFrame.corr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestSparseDataFrame
# 需要导入模块: from pandas.sparse.api import SparseDataFrame [as 别名]
# 或者: from pandas.sparse.api.SparseDataFrame import corr [as 别名]
#.........这里部分代码省略.........
result = df.copy()
result.fillna(0, inplace=True)
expected = dense.fillna(0)
tm.assert_sp_frame_equal(result, expected.to_sparse(fill_value=0),
exact_indices=False)
tm.assert_frame_equal(result.to_dense(), expected)
result = df.copy()
result = df['A']
result.fillna(0, inplace=True)
expected = dense['A'].fillna(0)
# this changes internal SparseArray repr
# tm.assert_sp_series_equal(result, expected.to_sparse(fill_value=0))
tm.assert_series_equal(result.to_dense(), expected)
def test_fillna_fill_value(self):
df = pd.DataFrame({'A': [1, 0, 0], 'B': [np.nan, np.nan, 4]})
sparse = pd.SparseDataFrame(df)
tm.assert_frame_equal(sparse.fillna(-1).to_dense(),
df.fillna(-1), check_dtype=False)
sparse = pd.SparseDataFrame(df, default_fill_value=0)
tm.assert_frame_equal(sparse.fillna(-1).to_dense(),
df.fillna(-1), check_dtype=False)
def test_rename(self):
# just check this works
renamed = self.frame.rename(index=str) # noqa
renamed = self.frame.rename(columns=lambda x: '%s%d' % (x, len(x))) # noqa
def test_corr(self):
res = self.frame.corr()
tm.assert_frame_equal(res, self.frame.to_dense().corr())
def test_describe(self):
self.frame['foo'] = np.nan
self.frame.get_dtype_counts()
str(self.frame)
desc = self.frame.describe() # noqa
def test_join(self):
left = self.frame.ix[:, ['A', 'B']]
right = self.frame.ix[:, ['C', 'D']]
joined = left.join(right)
tm.assert_sp_frame_equal(joined, self.frame, exact_indices=False)
right = self.frame.ix[:, ['B', 'D']]
self.assertRaises(Exception, left.join, right)
with tm.assertRaisesRegexp(ValueError,
'Other Series must have a name'):
self.frame.join(Series(
np.random.randn(len(self.frame)), index=self.frame.index))
def test_reindex(self):
def _check_frame(frame):
index = frame.index
sidx = index[::2]
sidx2 = index[:5] # noqa
sparse_result = frame.reindex(sidx)
dense_result = frame.to_dense().reindex(sidx)
示例2: TestSparseDataFrame
# 需要导入模块: from pandas.sparse.api import SparseDataFrame [as 别名]
# 或者: from pandas.sparse.api.SparseDataFrame import corr [as 别名]
#.........这里部分代码省略.........
applied = self.frame.apply(np.sqrt)
self.assert_(isinstance(applied, SparseDataFrame))
assert_almost_equal(applied.values, np.sqrt(self.frame.values))
applied = self.fill_frame.apply(np.sqrt)
self.assert_(applied["A"].fill_value == np.sqrt(2))
# agg / broadcast
applied = self.frame.apply(np.sum)
assert_series_equal(applied, self.frame.to_dense().apply(np.sum))
broadcasted = self.frame.apply(np.sum, broadcast=True)
self.assert_(isinstance(broadcasted, SparseDataFrame))
assert_frame_equal(broadcasted.to_dense(), self.frame.to_dense().apply(np.sum, broadcast=True))
self.assert_(self.empty.apply(np.sqrt) is self.empty)
def test_applymap(self):
# just test that it works
result = self.frame.applymap(lambda x: x * 2)
self.assert_(isinstance(result, SparseDataFrame))
def test_astype(self):
self.assertRaises(Exception, self.frame.astype, np.int64)
def test_fillna(self):
self.assertRaises(NotImplementedError, self.frame.fillna, 0)
def test_rename(self):
# just check this works
renamed = self.frame.rename(index=str)
renamed = self.frame.rename(columns=lambda x: "%s%d" % (x, len(x)))
def test_corr(self):
res = self.frame.corr()
assert_frame_equal(res, self.frame.to_dense().corr())
def test_describe(self):
self.frame["foo"] = np.nan
desc = self.frame.describe()
def test_join(self):
left = self.frame.ix[:, ["A", "B"]]
right = self.frame.ix[:, ["C", "D"]]
joined = left.join(right)
assert_sp_frame_equal(joined, self.frame)
right = self.frame.ix[:, ["B", "D"]]
self.assertRaises(Exception, left.join, right)
def test_reindex(self):
def _check_frame(frame):
index = frame.index
sidx = index[::2]
sidx2 = index[:5]
sparse_result = frame.reindex(sidx)
dense_result = frame.to_dense().reindex(sidx)
assert_frame_equal(sparse_result.to_dense(), dense_result)
assert_frame_equal(frame.reindex(list(sidx)).to_dense(), dense_result)
sparse_result2 = sparse_result.reindex(index)
dense_result2 = dense_result.reindex(index)
assert_frame_equal(sparse_result2.to_dense(), dense_result2)