pyspssio.Writer

class pyspssio.Writer(*args, **kwargs)[source]

Bases: Header

Class for writing SPSS file

__init__(*args, **kwargs)[source]

Methods

__init__(*args, **kwargs)

close()

Close file

commit_case_record()

Commit case record

commit_header()

Finalize metadata

open()

Open file

set_locale(locale)

Set I/O module to a specific locale

write_data(df, **kwargs)

Write data to file

write_data_by_val(df)

Write data by variable/value

write_header(df[, metadata])

Write metadata properties

Attributes

case_count

Number of cases

case_size

Record case size (in bytes)

case_weight_var

Case weight variable

compression

Compression level

file_attributes

Arbitrary user-defined file attributes

file_encoding

File encoding reported by I/O module

interface_encoding

I/O interface mode (Unicode or code page)

is_compatible_encoding

Check encoding compatibility

mrsets

Multi response set definitions

mrsets_count

Number of multi response set definitions

release_info

Basic file information

var_alignments

Variable alignments

var_attributes

Variable attributes

var_column_widths

Column display widths

var_compat_names

Short (8-byte) variable names

var_count

Number of variables

var_formats

Variable formats as strings

var_formats_tuple

Variable formats as tuples in the form (type, width, decimals)

var_handles

Variable handles references

var_labels

Variable labels

var_measure_levels

Variable measure levels

var_missing_values

Missing values

var_names

Variable names

var_roles

Variable roles

var_sets

Variable sets

var_types

Variable types

var_value_labels

Variable value labels

commit_case_record()[source]

Commit case record

Call function after setting values with set_value Do not use with whole_case_out

write_header(df, metadata=None, **kwargs)[source]

Write metadata properties

Parameters:
  • df (DataFrame) – DataFrame

  • metadata (Union[dict, SimpleNamespace] (default: None)) – Dictionary of Header attributes to use (see Header class for more detail)

  • **kwargs – Additional arguments, including individual metadata attributes. Note that metadata attributes supplied here take precedence.

write_data_by_val(df)[source]

Write data by variable/value

Parameters:

df (DataFrame) – DataFrame

Notes

Slower than whole_case_out Use when appending to an existing data set and variable order doesn’t align

write_data(df, **kwargs)[source]

Write data to file

Parameters:

df (DataFrame) – DataFrame