本文整理汇总了Python中pandas.core.generic.NDFrame.astype方法的典型用法代码示例。如果您正苦于以下问题:Python NDFrame.astype方法的具体用法?Python NDFrame.astype怎么用?Python NDFrame.astype使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.core.generic.NDFrame
的用法示例。
在下文中一共展示了NDFrame.astype方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestNDFrame
# 需要导入模块: from pandas.core.generic import NDFrame [as 别名]
# 或者: from pandas.core.generic.NDFrame import astype [as 别名]
class TestNDFrame(unittest.TestCase):
_multiprocess_can_split_ = True
def setUp(self):
tdf = t.makeTimeDataFrame()
self.ndf = NDFrame(tdf._data)
def test_constructor(self):
# with cast
ndf = NDFrame(self.ndf._data, dtype=np.int64)
self.assert_(ndf.values.dtype == np.int64)
def test_ndim(self):
self.assertEquals(self.ndf.ndim, 2)
def test_astype(self):
casted = self.ndf.astype(int)
self.assert_(casted.values.dtype == np.int_)
casted = self.ndf.astype(np.int32)
self.assert_(casted.values.dtype == np.int32)
def test_squeeze(self):
# noop
for s in [ t.makeFloatSeries(), t.makeStringSeries(), t.makeObjectSeries() ]:
t.assert_series_equal(s.squeeze(),s)
for df in [ t.makeTimeDataFrame() ]:
t.assert_frame_equal(df.squeeze(),df)
for p in [ t.makePanel() ]:
t.assert_panel_equal(p.squeeze(),p)
for p4d in [ t.makePanel4D() ]:
t.assert_panel4d_equal(p4d.squeeze(),p4d)
# squeezing
df = t.makeTimeDataFrame().reindex(columns=['A'])
t.assert_series_equal(df.squeeze(),df['A'])
p = t.makePanel().reindex(items=['ItemA'])
t.assert_frame_equal(p.squeeze(),p['ItemA'])
p = t.makePanel().reindex(items=['ItemA'],minor_axis=['A'])
t.assert_series_equal(p.squeeze(),p.ix['ItemA',:,'A'])
p4d = t.makePanel4D().reindex(labels=['label1'])
t.assert_panel_equal(p4d.squeeze(),p4d['label1'])
p4d = t.makePanel4D().reindex(labels=['label1'],items=['ItemA'])
t.assert_frame_equal(p4d.squeeze(),p4d.ix['label1','ItemA'])
示例2: TestNDFrame
# 需要导入模块: from pandas.core.generic import NDFrame [as 别名]
# 或者: from pandas.core.generic.NDFrame import astype [as 别名]
class TestNDFrame(unittest.TestCase):
def setUp(self):
tdf = t.makeTimeDataFrame()
self.ndf = NDFrame(tdf._data)
def test_constructor(self):
# with cast
ndf = NDFrame(self.ndf._data, dtype=np.int64)
self.assert_(ndf.values.dtype == np.int64)
def test_ndim(self):
self.assertEquals(self.ndf.ndim, 2)
def test_astype(self):
casted = self.ndf.astype(int)
self.assert_(casted.values.dtype == np.int64)