fcapy.context.converters

This module provides a number of functions to read/write FormalContext object from/to a file

Functions

from_pandas(dataframe)

Create FormalContext object based on pandas.DataFrame

read_csv(path[, sep, word_true, word_false])

Read FormalContext from .csv file

read_cxt([path, data])

Read FormalContext from .cxt file or from data attribute

read_json([path, data])

Read FormalContext from .json file or from data attribute

to_pandas(context)

Convert FormalContext object to pandas.DataFrame object

write_csv(context[, path, sep, word_true, …])

Write FormalContext object to the .csv file

write_cxt(context[, path])

Write FormalContext object to the .cxt file

write_json(context[, path])

Write FormalContext object to the .json file

fcapy.context.converters.from_pandas(dataframe)

Create FormalContext object based on pandas.DataFrame

context.object_names are parsed from dataframe.index. context.column_names are parsed from dataframe.columns

Parameters

dataframe (pandas.DataFrame) –

Returns

ctx

Return type

FormalContext

fcapy.context.converters.read_csv(path, sep=',', word_true='True', word_false='False')

Read FormalContext from .csv file

Parameters
  • path (str) – A path to requested .csv file

  • sep (str) – A separator in the .csv file

  • word_true (str) – A string placeholder corresponding to True values in the .csv file

  • word_false (str) – A string placeholder corresponding to False values in the .csv file

Returns

ctx – The loaded FormalContext object

Return type

FormalContext

fcapy.context.converters.read_cxt(path=None, data=None)

Read FormalContext from .cxt file or from data attribute

Parameters
  • path (str) – A path to requested .cxt file

  • data (str) – CXT formatted data (if it is already loaded into python)

Returns

ctx – The loaded FormalContext object

Return type

FormalContext

fcapy.context.converters.read_json(path=None, data=None)

Read FormalContext from .json file or from data attribute

Parameters
  • path (str) – A path to requested .json file

  • data (str) – JSON formatted data (if it is already loaded into python)

Returns

ctx – The loaded FormalContext object

Return type

FormalContext

fcapy.context.converters.to_pandas(context)

Convert FormalContext object to pandas.DataFrame object

context.object_names are turned into df.index. context.column_names are turned into df.columns

Parameters

context (FormalContext) – A context to convert

Returns

df – The binary dataframe based on FormalContext object

Return type

pandas.DataFrame

fcapy.context.converters.write_csv(context, path=None, sep=',', word_true='True', word_false='False')

Write FormalContext object to the .csv file

Parameters
  • context (FormalContext) – A context to write to a file

  • path (str) – A path to the file to write a FormalContext object

  • sep (str) – A separator in the .csv file

  • word_true (str) – A string placeholder corresponding to True values in the .csv file

  • word_false (str) – A string placeholder corresponding to False values in the .csv file

Returns

file_data – The date from the .csv file. Returned if path is None

Return type

str

fcapy.context.converters.write_cxt(context, path=None)

Write FormalContext object to the .cxt file

Parameters
  • context (FormalContext) – A context to write to a file

  • path (str) – A path to the file to write a FormalContext object

Returns

file_data – The date from the .cxt file. Returned if path is None

Return type

str

fcapy.context.converters.write_json(context, path=None)

Write FormalContext object to the .json file

Parameters
  • context (FormalContext) – A context to write to a file

  • path (str) – A path to the file to write a FormalContext object

Returns

file_data – The date from the .json file. Returned if path is None

Return type

str