本文整理汇总了Python中pandas.compat.BytesIO.close方法的典型用法代码示例。如果您正苦于以下问题:Python BytesIO.close方法的具体用法?Python BytesIO.close怎么用?Python BytesIO.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.compat.BytesIO
的用法示例。
在下文中一共展示了BytesIO.close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_stringio_writer
# 需要导入模块: from pandas.compat import BytesIO [as 别名]
# 或者: from pandas.compat.BytesIO import close [as 别名]
def test_stringio_writer(self):
_skip_if_no_xlsxwriter()
_skip_if_no_xlrd()
path = BytesIO()
with ExcelWriter(path, engine='xlsxwriter', **{'options': {'in-memory': True}}) as ew:
self.frame.to_excel(ew, 'test1', engine='xlsxwriter')
ew.save()
path.seek(0)
ef = ExcelFile(path)
found_df = ef.parse('test1')
tm.assert_frame_equal(self.frame, found_df)
path.close()
示例2: test_utf16_bom_skiprows
# 需要导入模块: from pandas.compat import BytesIO [as 别名]
# 或者: from pandas.compat.BytesIO import close [as 别名]
def test_utf16_bom_skiprows(self):
# #2298
data = u(
"""skip this
skip this too
A\tB\tC
1\t2\t3
4\t5\t6"""
)
data2 = u(
"""skip this
skip this too
A,B,C
1,2,3
4,5,6"""
)
path = "__%s__.csv" % tm.rands(10)
with tm.ensure_clean(path) as path:
for sep, dat in [("\t", data), (",", data2)]:
for enc in ["utf-16", "utf-16le", "utf-16be"]:
bytes = dat.encode(enc)
with open(path, "wb") as f:
f.write(bytes)
s = BytesIO(dat.encode("utf-8"))
if compat.PY3:
# somewhat False since the code never sees bytes
from io import TextIOWrapper
s = TextIOWrapper(s, encoding="utf-8")
result = self.read_csv(path, encoding=enc, skiprows=2, sep=sep)
expected = self.read_csv(s, encoding="utf-8", skiprows=2, sep=sep)
s.close()
tm.assert_frame_equal(result, expected)