本文整理汇总了Python中pandas.util.py3compat.StringIO.getvalue方法的典型用法代码示例。如果您正苦于以下问题:Python StringIO.getvalue方法的具体用法?Python StringIO.getvalue怎么用?Python StringIO.getvalue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.util.py3compat.StringIO
的用法示例。
在下文中一共展示了StringIO.getvalue方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pandas.util.py3compat import StringIO [as 别名]
# 或者: from pandas.util.py3compat.StringIO import getvalue [as 别名]
class UnicodeWriter:
"""
A CSV writer which will write rows to CSV file "f",
which is encoded in the given encoding.
"""
def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
# Redirect output to a queue
self.queue = StringIO()
self.writer = csv.writer(self.queue, dialect=dialect, **kwds)
self.stream = f
self.encoder = codecs.getincrementalencoder(encoding)()
def writerow(self, row):
row = [x if isinstance(x, basestring) else str(x) for x in row]
self.writer.writerow([s.encode("utf-8") for s in row])
# Fetch UTF-8 output from the queue ...
data = self.queue.getvalue()
data = data.decode("utf-8")
# ... and reencode it into the target encoding
data = self.encoder.encode(data)
# write to the target stream
self.stream.write(data)
# empty queue
self.queue.truncate(0)
示例2: _coef_table
# 需要导入模块: from pandas.util.py3compat import StringIO [as 别名]
# 或者: from pandas.util.py3compat.StringIO import getvalue [as 别名]
def _coef_table(self):
buffer = StringIO()
buffer.write('%13s %13s %13s %13s %13s %13s\n' %
('Variable', 'Beta', 'Std Err', 't-stat', 'CI 2.5%', 'CI 97.5%'))
template = '%13s %13.4f %13.4f %13.2f %13.4f %13.4f\n'
for i, name in enumerate(self._cols):
if i and not (i % 5):
buffer.write('\n' + common.banner(''))
mean_beta = self._results['mean_beta'][i]
std_beta = self._results['std_beta'][i]
t_stat = self._results['t_stat'][i]
ci1 = mean_beta - 1.96 * std_beta
ci2 = mean_beta + 1.96 * std_beta
values = '(%s)' % name, mean_beta, std_beta, t_stat, ci1, ci2
buffer.write(template % values)
if self._nw_lags_beta is not None:
buffer.write('\n')
buffer.write('*** The Std Err, t-stat are Newey-West '
'adjusted with Lags %5d\n' % self._nw_lags_beta)
return buffer.getvalue()
示例3: __init__
# 需要导入模块: from pandas.util.py3compat import StringIO [as 别名]
# 或者: from pandas.util.py3compat.StringIO import getvalue [as 别名]
class UnicodeWriter:
"""
A CSV writer which will write rows to CSV file "f",
which is encoded in the given encoding.
"""
def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
# Redirect output to a queue
self.queue = StringIO()
self.writer = csv.writer(self.queue, dialect=dialect, **kwds)
self.stream = f
self.encoder = codecs.getincrementalencoder(encoding)()
self.quoting = kwds.get("quoting", None)
def writerow(self, row):
def _check_as_is(x):
return (self.quoting == csv.QUOTE_NONNUMERIC and
is_number(x)) or isinstance(x, str)
row = [x if _check_as_is(x)
else pprint_thing(x).encode('utf-8') for x in row]
self.writer.writerow([s for s in row])
# Fetch UTF-8 output from the queue ...
data = self.queue.getvalue()
data = data.decode("utf-8")
# ... and reencode it into the target encoding
data = self.encoder.encode(data)
# write to the target stream
self.stream.write(data)
# empty queue
self.queue.truncate(0)
示例4: generate_from_template
# 需要导入模块: from pandas.util.py3compat import StringIO [as 别名]
# 或者: from pandas.util.py3compat.StringIO import getvalue [as 别名]
def generate_from_template(template, ndim=1, exclude=None):
output = StringIO()
for name, c_type, dtype, can_hold_na in function_list:
if exclude is not None and name in exclude:
continue
func = template % {'name': name, 'c_type': c_type,
'dtype': dtype,
'raise_on_na': 'False' if can_hold_na else 'True'}
output.write(func)
return output.getvalue()
示例5: test_verbose_import
# 需要导入模块: from pandas.util.py3compat import StringIO [as 别名]
# 或者: from pandas.util.py3compat.StringIO import getvalue [as 别名]
def test_verbose_import(self):
text = """a,b,c,d
one,1,2,3
one,1,2,3
,1,2,3
one,1,2,3
,1,2,3
,1,2,3
one,1,2,3
two,1,2,3"""
buf = StringIO()
sys.stdout = buf
try:
# it works!
df = read_csv(StringIO(text), verbose=True)
self.assert_(buf.getvalue() == 'Filled 3 NA values in column a\n')
finally:
sys.stdout = sys.__stdout__
buf = StringIO()
sys.stdout = buf
text = """a,b,c,d
one,1,2,3
two,1,2,3
three,1,2,3
four,1,2,3
five,1,2,3
,1,2,3
seven,1,2,3
eight,1,2,3"""
try:
# it works!
df = read_csv(StringIO(text), verbose=True, index_col=0)
self.assert_(buf.getvalue() == 'Found 1 NA values in the index\n')
finally:
sys.stdout = sys.__stdout__
示例6: generate_put_functions
# 需要导入模块: from pandas.util.py3compat import StringIO [as 别名]
# 或者: from pandas.util.py3compat.StringIO import getvalue [as 别名]
def generate_put_functions():
function_list = [
('float64', 'float64_t', 'object'),
('float64', 'float64_t', 'float64_t'),
('object', 'object', 'object'),
('int32', 'int32_t', 'int64_t'),
('int32', 'int32_t', 'float64_t'),
('int32', 'int32_t', 'object'),
('int64', 'int64_t', 'int64_t'),
('int64', 'int64_t', 'float64_t'),
('int64', 'int64_t', 'object'),
('bool', 'uint8_t', 'uint8_t'),
('bool', 'uint8_t', 'object')
]
output = StringIO()
for name, c_type, dest_type in function_list:
func = put2d_template % {'name' : name, 'c_type' : c_type,
'dest_type' : dest_type.replace('_t', ''),
'dest_type2' : dest_type}
output.write(func)
return output.getvalue()
示例7: generate_ensure_dtypes
# 需要导入模块: from pandas.util.py3compat import StringIO [as 别名]
# 或者: from pandas.util.py3compat.StringIO import getvalue [as 别名]
def generate_ensure_dtypes():
output = StringIO()
for name, ctype, dtype in ensure_functions:
filled = ensure_dtype_template % locals()
output.write(filled)
return output.getvalue()