write#
- hollerith._writer.write_int_to_buffer(buffer, int value, int width)#
Writes a string representing the int
value
tobuffer
within the givenwidth
, right justified.- Parameters:
Examples
>>> import io >>> import hollerith as holler >>> buffer = io.StringIO() >>> holler.write_int(buffer, 145, 16) >>> print(buffer.getvalue()) ' 145'
- hollerith._writer.write_float_to_buffer(buffer, double value, int width)#
Writes a string representing the float
value
tobuffer
within the givenwidth
, right justified.- Parameters:
Examples
>>> import io >>> import hollerith as holler >>> buffer = io.StringIO() >>> holler.write_float(buffer, 1.0, 16) >>> print(buffer.getvalue()) ' 1.0'
- hollerith._writer.write_string_to_buffer(buffer, unicode value, int width)#
Writes a string representing the string
value
tobuffer
within the givenwidth
, left justified.- Parameters:
Examples
>>> import io >>> import hollerith as holler >>> buffer = io.StringIO() >>> holler.write_string(s, "hello", 16) >>> print(buffer.getvalue()) 'hello '
- hollerith._writer.write_null_to_buffer(buffer, int width)#
Writes
width
space characters tobuffer
- Parameters:
- buffer
Buffer to write to - it could be a file or a StringIO object, for example. The only requirement is that it must contain a write attribute that is callable with a single string argument.
- width
int
The number of spaces to write
Examples
>>> import io >>> import hollerith as holler >>> buffer = io.StringIO() >>> holler.write_spaces(buffer, 16) >>> print(buffer.getvalue()) ' '
- hollerith.write_table(buffer, table: DataFrame, numrows: int, spec: List[Field])#
Write table to buffer with fixed width columns
- Parameters:
- buffer
Buffer to write to - it could be a file or a StringIO object, for example. The only requirement is that it must contain a write attribute that is callable with a single string argument.
- table
pandas.DataFrame
Table to write.
- numrows
int
The number of rows to write. This might be larger than the length of table. If so, append with empty lines with the right size.
- spec
List
[hollerith.Field
] Specification of the table. Must be the same length as the number of columns in table.
Notes
Here, we convert the table to a numpy 2-d array with a type of object in order to call
write_numpy_table
. Numpy arrays of a narrower type are possible, such as arrays of ints or floats, and this conversion can be expensive. A future optimization would be to expose Cython-level methods in _writer.Examples
>>> import io >>> import hollerith as holler >>> import pandas as pd >>> buffer = io.StringIO() >>> spec = [holler.Field(float, 20), holler.Field(float, 20)] >>> table = pd.DataFrame({"a": [1.0, 3.0, 5.0], "b": [2.0, 4.0, 6.0]}) >>> result = holler.write_table(buffer, table, 3, spec) >>> print(buffer.getvalue()) ' 1.0 2.0 3.0 4.0 5.0 6.0'