create-intro-cards¶
- class create_intro_cards.StatsDict¶
Metadata about a given run of the intro card creation process.
- number_of_cards_created: int¶
The total number of intro cards that were created.
- number_of_cards_to_create: int¶
The number of people for whom cards needed to be generated.
- people_with_photo_warnings: list[str]¶
The names of people whose photos could not be found or read.
- create_intro_cards.make_pdf(people_data: DataFrame, first_name_col: str, last_name_col: str, photo_path_col: str, path_to_default_photo: str, path_to_output_dir: str = './intro_cards_output', figure_size: tuple[float, float] = (23, 13), name_x_coord: float = 0.35, name_y_coord: float = 0.95, name_font_size: float = 50, desc_padding: float = 0.05, desc_font_size: float = 16, photo_axes_bounds: tuple[float, float, float, float] = (0.02, 0.02, 0.3, 0.93)) StatsDict ¶
Generate a PDF containing intro cards for all individuals in
people_data
.This is entry point of the package. It generates a PDF, where each page of the PDF is a single Matplotlib figure, which is itself composed of four individuals’ intro cards. Each intro card contains an individual’s name, a photo (either provided or default), and a description that displays their “column name: attribute value” pairings for each custom column in
people_data
(i.e., columns not related to name and photo path).On each intro card, “column name: attribute value” pairings are separated by a new line, and each “column name” is rendered in bold. Text on any given line is wrapped such that it approaches—but does not touch—the right border of the card. If an individual’s “attribute value” is left blank, that particular “column name: attribute value” pairing will be omitted from their card. Note that if the name of a custom column contains
~
,^
, or\
, that character will be removed from the column name on the intro card.This function also provides parameters to tweak the formatting and layout of all individuals’ intro cards, such as
name_x_coord
,desc_padding
, andphoto_axes_bounds
. Usingmake_pdf_preview()
(Jupyter environment required) allows for quick feedback on how these parameters affect the cards.The output PDF is saved down in
path_to_output_dir
. Also in this directory are the constituent pages of the PDF (PNG images of the Matplotlib figures, as rendered using the Agg backend) and a log file that denotes the names and photo availability statuses of all the individuals who had an intro card created. Depending on the number of individuals, the file size of the PDF might be quite large; to reduce it (at the expense of resolution), scale down each number infigure_size
,name_font_size
, anddesc_font_size
by a common factor.The function returns a dictionary with metadata pertaining to the number of intro cards that were created, the number of people for whom cards needed to be generated, and the names of people whose photos could not be found or read.
- Parameters:
people_data (pd.DataFrame) – The pandas DataFrame containing all the data from which to make intro cards. Rows represent individuals, while columns represent attributes of those individuals. The choice of attributes is completely up to the user (e.g., “Hometown”, “Fun Fact”), but it is required that there be columns for first name, last name, and paths to individuals’ photos (which will ultimately be displayed on their respective intro cards). The name of each column—except the ones for first name, last name, and photo paths—will ultimately end up being listed on individuals’ intro cards in bold. The order of these columns dictates the order in which “column name: attribute value” pairings are displayed on the cards.
first_name_col (str) – The name of the column (Series) in
people_data
that houses first nameslast_name_col (str) – The name of the column (Series) in
people_data
that houses last namesphoto_path_col (str) – The name of the column (Series) in
people_data
that houses paths to individuals’ photos. The photos must be of a type that Pillow supports (e.g., PNG, JPG). Paths can be relative or absolute.path_to_default_photo (str) – The path to the photo to use if an individual does not have a photo path listed
people_data
. This default photo will also be used if there is indeed a photo path specified but the photo cannot be found at that location. The photo must be of a type that Pillow supports (e.g., PNG, JPG). If specifying this argument using a single-backlash separator, make sure to use a raw string.path_to_output_dir (str, optional) – The path to the output directory to use. The output directory will store the final PDF, its constituent pages/Matplob figures, and the log file. If it does not exist, it will be created at runtime. If specifying this argument using a single-backlash separator, make sure to use a raw string., defaults to ‘intro_cards_output’
figure_size (tuple[float, float], optional) – The size of the figure that Matplotlib will create when plotting a batch of four intro cards on it. The first entry in this tuple is the width of the figure and the second is the height (both in inches). Each figure will ultimately become its own page in the PDF., defaults to (23, 13)
name_x_coord (float, optional) – The (Axes-relative) x-coordinate of individuals’ names on their intro cards (which are Matplotlib Axes). This will also be the x-coordinate of individuals’ descriptions., defaults to 0.35
name_y_coord (float, optional) – The (Axes-relative) y-coordinate of individuals’ names on their intro cards (which are Matplotlib Axes), defaults to 0.95
name_font_size (float, optional) – The font size of individuals’ names on their intro cards, defaults to 50
desc_padding (float, optional) – The amount of padding (in Axes-relative coordinates) below the lower bound of the name’s bounding box, after which to begin plotting the individual’s description, defaults to 0.05
desc_font_size (float, optional) – The font size of individuals’ descriptions on their intro cards. If this font size would cause the lower bound of the description’s bounding box to come within 0.02 of the bottom of any individual’s intro card (or even exceed it and be cut off), then this font size will be iteratively reduced by 5% on that specific intro card until this is no longer the case., defaults to 16
photo_axes_bounds (tuple[float, float, float, float], optional) – The bounds of the photo Axes on individuals’ intro cards (the photo Axes is inset within the main intro card Axes). The bounds should be given as (x0, y0, width, height), where x0 and y0 represent the lower-left corner of the photo Axes. The photo will ultimately grow from the upper-left corner of this bounding box with a fixed aspect ratio. All coordinates are Axes- relative., defaults to (0.02, 0.02, 0.3, 0.93)
- Raises:
OSError – If the default photo does not exist at the specified path, or if the default photo cannot be read by PIL, or if the specified output directory does not exist and then cannot be created
ValueError – If
first_name_col
,last_name_col
, orphoto_path_col
cannot be found inpeople_data
- Returns:
Metadata pertaining to the number of intro cards that were created, the number of people for whom cards needed to be generated, and the names of people whose photos could not be found or read
- Return type:
- create_intro_cards.make_pdf_preview(people_data: DataFrame, first_name_col: str, last_name_col: str, photo_path_col: str, path_to_default_photo: str, figure_size: tuple[float, float] = (23, 13), name_x_coord: float = 0.35, name_y_coord: float = 0.95, name_font_size: float = 50, desc_padding: float = 0.05, desc_font_size: float = 16, photo_axes_bounds: tuple[float, float, float, float] = (0.02, 0.02, 0.3, 0.93)) StatsDict ¶
Show a preview in a Jupyter environment of the first page of the PDF that would be created if
make_pdf()
were run, and print log output to the console.This function is helpful to gauge how the output will look in response to tweaking certain parameters (e.g.,
name_font_size
) without having to actually iterate through the entirety ofpeople_data
and compile the PDF. Its parameters, defaults, and return type are identical to those ofmake_pdf()
, except for its omission ofpath_to_output_dir
. It serves primarily as a wrapper for_make_fig_preview()
to allow for more consistent naming in the public API.Because this function uses Matplotlib’s inline backend, it is required to be run in a Jupyter environment. The figures displayed by this backend ultimately match those that are rendered by the Agg backend that is implicitly used in each of
make_pdf()
’sfig.savefig()
calls.- Parameters:
people_data (pd.DataFrame) – The pandas DataFrame containing all the data from which to make intro cards. Rows represent individuals, while columns represent attributes of those individuals. The choice of attributes is completely up to the user (e.g., “Hometown”, “Fun Fact”), but it is required that there be columns for first name, last name, and paths to individuals’ photos (which will ultimately be displayed on their respective intro cards). The name of each column—except the ones for first name, last name, and photo paths—will ultimately end up being listed on individuals’ intro cards in bold. The order of these columns dictates the order in which “column name: attribute value” pairings are displayed on the cards.
first_name_col (str) – The name of the column (Series) in
people_data
that houses first nameslast_name_col (str) – The name of the column (Series) in
people_data
that houses last namesphoto_path_col (str) – The name of the column (Series) in
people_data
that houses paths to individuals’ photos. The photos must be of a type that Pillow supports (e.g., PNG, JPG). Paths can be relative or absolute.path_to_default_photo (str) – The path to the photo to use if an individual does not have a photo path listed
people_data
. This default photo will also be used if there is indeed a photo path specified but the photo cannot be found at that location. The photo must be of a type that Pillow supports (e.g., PNG, JPG). If specifying this argument using a single-backlash separator, make sure to use a raw string.figure_size (tuple[float, float], optional) – The size of the figure that Matplotlib will create when plotting a batch of four intro cards on it. The first entry in this tuple is the width of the figure and the second is the height (both in inches). Each figure will ultimately become its own page in the PDF., defaults to (23, 13)
name_x_coord (float, optional) – The (Axes-relative) x-coordinate of individuals’ names on their intro cards (which are Matplotlib Axes). This will also be the x-coordinate of individuals’ descriptions., defaults to 0.35
name_y_coord (float, optional) – The (Axes-relative) y-coordinate of individuals’ names on their intro cards (which are Matplotlib Axes), defaults to 0.95
name_font_size (float, optional) – The font size of individuals’ names on their intro cards, defaults to 50
desc_padding (float, optional) – The amount of padding (in Axes-relative coordinates) below the lower bound of the name’s bounding box, after which to begin plotting the individual’s description, defaults to 0.05
desc_font_size (float, optional) – The font size of individuals’ descriptions on their intro cards. If this font size would cause the lower bound of the description’s bounding box to come within 0.02 of the bottom of any individual’s intro card (or even exceed it and be cut off), then this font size will be iteratively reduced by 5% on that specific intro card until this is no longer the case., defaults to 16
photo_axes_bounds (tuple[float, float, float, float], optional) – The bounds of the photo Axes on individuals’ intro cards (the photo Axes is inset within the main intro card Axes). The bounds should be given as (x0, y0, width, height), where x0 and y0 represent the lower-left corner of the photo Axes. The photo will ultimately grow from the upper-left corner of this bounding box with a fixed aspect ratio. All coordinates are Axes- relative., defaults to (0.02, 0.02, 0.3, 0.93)
- Raises:
OSError – If the default photo does not exist at the specified path, or if the default photo cannot be read by PIL
ValueError – If
first_name_col
,last_name_col
, orphoto_path_col
cannot be found inpeople_data
- Returns:
Metadata pertaining to the number of intro cards that were created, the number of people for whom cards needed to be generated, and the names of people whose photos could not be found or read
- Return type:
- create_intro_cards._make_figs(people_data: DataFrame, first_name_col: str, last_name_col: str, photo_path_col: str, path_to_default_photo: str, path_to_output_dir: str, figure_size: tuple[float, float], name_x_coord: float, name_y_coord: float, name_font_size: float, desc_padding: float, desc_font_size: float, photo_axes_bounds: tuple[float, float, float, float], stats: StatsDict) None ¶
Iteratively grab batches of four rows (individuals) from
people_data
, and for each batch save a Matplotlib figure that shows those four individuals’ intro cards. Private function.All figures will be saved as PNG files in
path_to_output_dir
. If the number of rows inpeople_data
is not divisible by 4, the last figure will show only as many individuals are needed to account for every individual in the DataFrame.- Parameters:
people_data (pd.DataFrame) – The pandas DataFrame containing all the data from which to make intro cards. Rows represent individuals, while columns represent attributes of those individuals. The choice of attributes is completely up to the user (e.g., “Hometown”, “Fun Fact”), but it is required that there be columns for first name, last name, and paths to individuals’ photos (which will ultimately be displayed on their respective intro cards). The name of each column—except the ones for first name, last name, and photo paths—will ultimately end up being listed on individuals’ intro cards in bold. The order of these columns dictates the order in which “column name: attribute value” pairings are displayed on the cards.
first_name_col (str) – The name of the column (Series) in
people_data
that houses first nameslast_name_col (str) – The name of the column (Series) in
people_data
that houses last namesphoto_path_col (str) – The name of the column (Series) in
people_data
that houses paths to individuals’ photos. The photos must be of a type that Pillow supports (e.g., PNG, JPG). Paths can be relative or absolute.path_to_default_photo (str) – The path to the photo to use if an individual does not have a photo path listed
people_data
. This default photo will also be used if there is indeed a photo path specified but the photo cannot be found at that location. The photo must be of a type that Pillow supports (e.g., PNG, JPG). If specifying this argument using a single-backlash separator, make sure to use a raw string.path_to_output_dir (str) – The path to the output directory to use. The output directory will store the final PDF, its constituent pages/Matplob figures, and the log file. If it does not exist, it will be created at runtime. If specifying this argument using a single-backlash separator, make sure to use a raw string.
figure_size (tuple[float, float]) – The size of the figure that Matplotlib will create when plotting a batch of four intro cards on it. The first entry in this tuple is the width of the figure and the second is the height (both in inches). Each figure will ultimately become its own page in the PDF.
name_x_coord (float) – The (Axes-relative) x-coordinate of individuals’ names on their intro cards (which are Matplotlib Axes). This will also be the x-coordinate of individuals’ descriptions.
name_y_coord (float) – The (Axes-relative) y-coordinate of individuals’ names on their intro cards (which are Matplotlib Axes)
name_font_size (float) – The font size of individuals’ names on their intro cards
desc_padding (float) – The amount of padding (in Axes-relative coordinates) below the lower bound of the name’s bounding box, after which to begin plotting the individual’s description
desc_font_size (float) – The font size of individuals’ descriptions on their intro cards. If this font size would cause the lower bound of the description’s bounding box to come within 0.02 of the bottom of any individual’s intro card (or even exceed it and be cut off), then this font size will be iteratively reduced by 5% on that specific intro card until this is no longer the case., defaults to 16
photo_axes_bounds (tuple[float, float, float, float]) – The bounds of the photo Axes on individuals’ intro cards (the photo Axes is inset within the main intro card Axes). The bounds should be given as (x0, y0, width, height), where x0 and y0 represent the lower-left corner of the photo Axes. The photo will ultimately grow from the upper-left corner of this bounding box with a fixed aspect ratio. All coordinates are Axes- relative.
stats (StatsDict) – Metadata pertaining to the number of intro cards that were created, the number of people for whom cards needed to be generated, and the names of people whose photos could not be found or read
- Returns:
None
- Return type:
NoneType
- create_intro_cards._make_fig_preview(people_data: DataFrame, first_name_col: str, last_name_col: str, photo_path_col: str, path_to_default_photo: str, figure_size: tuple[float, float], name_x_coord: float, name_y_coord: float, name_font_size: float, desc_padding: float, desc_font_size: float, photo_axes_bounds: tuple[float, float, float, float], stats: StatsDict) None ¶
Show a preview (using
plt.show()
) of the first page of the PDF that would be created ifmake_pdf()
were run. Private function.This function is called internally by
make_pdf_preview
to gauge how the output will look in response to tweaking certain parameters (e.g.,name_font_size
), without having to iterate through the entirety ofpeople_data
. Its parameters are identical to those of_make_figs()
, except for its omission ofpath_to_output_dir
.- Parameters:
people_data (pd.DataFrame) – The pandas DataFrame containing all the data from which to make intro cards. Rows represent individuals, while columns represent attributes of those individuals. The choice of attributes is completely up to the user (e.g., “Hometown”, “Fun Fact”), but it is required that there be columns for first name, last name, and paths to individuals’ photos (which will ultimately be displayed on their respective intro cards). The name of each column—except the ones for first name, last name, and photo paths—will ultimately end up being listed on individuals’ intro cards in bold. The order of these columns dictates the order in which “column name: attribute value” pairings are displayed on the cards.
first_name_col (str) – The name of the column (Series) in
people_data
that houses first nameslast_name_col (str) – The name of the column (Series) in
people_data
that houses last namesphoto_path_col (str) – The name of the column (Series) in
people_data
that houses paths to individuals’ photos. The photos must be of a type that Pillow supports (e.g., PNG, JPG). Paths can be relative or absolute.path_to_default_photo (str) – The path to the photo to use if an individual does not have a photo path listed
people_data
. This default photo will also be used if there is indeed a photo path specified but the photo cannot be found at that location. The photo must be of a type that Pillow supports (e.g., PNG, JPG). If specifying this argument using a single-backlash separator, make sure to use a raw string.figure_size (tuple[float, float]) – The size of the figure that Matplotlib will create when plotting a batch of four intro cards on it. The first entry in this tuple is the width of the figure and the second is the height (both in inches). Each figure will ultimately become its own page in the PDF.
name_x_coord (float) – The (Axes-relative) x-coordinate of individuals’ names on their intro cards (which are Matplotlib Axes). This will also be the x-coordinate of individuals’ descriptions.
name_y_coord (float) – The (Axes-relative) y-coordinate of individuals’ names on their intro cards (which are Matplotlib Axes)
name_font_size (float) – The font size of individuals’ names on their intro cards
desc_padding (float) – The amount of padding (in Axes-relative coordinates) below the lower bound of the name’s bounding box, after which to begin plotting the individual’s description
desc_font_size (float) – The font size of individuals’ descriptions on their intro cards. If this font size would cause the lower bound of the description’s bounding box to come within 0.02 of the bottom of any individual’s intro card (or even exceed it and be cut off), then this font size will be iteratively reduced by 5% on that specific intro card until this is no longer the case.
photo_axes_bounds (tuple[float, float, float, float]) – The bounds of the photo Axes on individuals’ intro cards (the photo Axes is inset within the main intro card Axes). The bounds should be given as (x0, y0, width, height), where x0 and y0 represent the lower-left corner of the photo Axes. The photo will ultimately grow from the upper-left corner of this bounding box with a fixed aspect ratio. All coordinates are Axes- relative.
stats (StatsDict) – Metadata pertaining to the number of intro cards that were created, the number of people for whom cards needed to be generated, and the names of people whose photos could not be found or read
- Returns:
None
- Return type:
NoneType
- create_intro_cards._make_card(row: Series, ax: Axes, first_name_col: str, last_name_col: str, photo_path_col: str, path_to_default_photo: str, name_x_coord: float, name_y_coord: float, name_font_size: float, desc_padding: float, desc_font_size: float, photo_axes_bounds: tuple[float, float, float, float], stats: StatsDict) None ¶
Create a single intro card by plotting an individual’s name, photo, and description on a Matplotlib Axes. Private function.
- Parameters:
row (pd.Series) – The row in
people_data
from which to create the intro card. Each row represents an individual.ax (mpl.axes.Axes) – The Matplotlib Axes object on which to plot the individual’s name, photo, and description string
first_name_col (str) – The name of the column (Series) in
people_data
that houses first nameslast_name_col (str) – The name of the column (Series) in
people_data
that houses last namesphoto_path_col (str) – The name of the column (Series) in
people_data
that houses paths to individuals’ photos. The photos must be of a type that Pillow supports (e.g., PNG, JPG). Paths can be relative or absolute.path_to_default_photo (str) – The path to the photo to use if an individual does not have a photo path listed
people_data
. This default photo will also be used if there is indeed a photo path specified but the photo cannot be found at that location. The photo must be of a type that Pillow supports (e.g., PNG, JPG). If specifying this argument using a single-backlash separator, make sure to use a raw string.figure_size (tuple[float, float]) – The size of the figure that Matplotlib will create when plotting a batch of four intro cards on it. The first entry in this tuple is the width of the figure and the second is the height (both in inches). Each figure will ultimately become its own page in the PDF.
name_x_coord (float) – The (Axes-relative) x-coordinate of the individual’s name on their intro card (which is a Matplotlib Axes). This will also be the x-coordinate of the individual’s description.
name_y_coord (float) – The (Axes-relative) y-coordinate of the individual’s name on their intro card (which is a Matplotlib Axes)
name_font_size (float) – The font size of the individual’s name on their intro card
desc_padding (float) – The amount of padding (in Axes-relative coordinates) below the lower bound of the name’s bounding box, after which to begin plotting the individual’s description
desc_font_size (float) – The font size of the individual’s description on their intro card. If this font size would cause the lower bound of the description’s bounding box to come within 0.02 of the bottom of any individual’s intro card (or even exceed it and be cut off), then this font size will be iteratively reduced by 5% on that specific intro card until this is no longer the case.
photo_axes_bounds (tuple[float, float, float, float]) – The bounds of the photo Axes on individuals’ intro cards (the photo Axes is inset within the main intro card Axes). The bounds should be given as (x0, y0, width, height), where x0 and y0 represent the lower-left corner of the photo Axes. The photo will ultimately grow from the upper-left corner of this bounding box with a fixed aspect ratio. All coordinates are Axes- relative.
stats (StatsDict) – Metadata pertaining to the number of intro cards that were created, the number of people for whom cards needed to be generated, and the names of people whose photos could not be found or read
- Returns:
None
- Return type:
NoneType
- create_intro_cards._get_description_string_from_row(row: Series, first_name_col: str, last_name_col: str, photo_path_col: str) str ¶
Return a string that, for a given row/individual, lists all their “column name: attribute value” pairings for each column in
people_data
(except columns related to names or photo path). Private function.Each “column name: attribute value” pairing is separated by a new line, and each “column name” is bolded (by wrapping it in appropriate Mathtext characters). Text on any given line is wrapped, such that it approaches—but does not touch—the right border of the card. If an individual’s “attribute value” is left blank, then that particular “column name: attribute value” pairing will be omitted from the description string.
- Parameters:
row (pd.Series) – The row in
people_data
to describe. Each row represents an individual.first_name_col (str) – The name of the column (Series) in
people_data
that houses first nameslast_name_col (str) – The name of the column (Series) in
people_data
that houses last namesphoto_path_col (str) – The name of the column (Series) in
people_data
that houses photo paths. Paths can be relative or absolute.
- Returns:
A formatted description string listing all the appropriate “column name: attribute value” pairings of row
- Return type:
str
- class create_intro_cards._WrapText(x: float = 0, y: float = 0, text: str = '', width: float = 0, widthcoords: Transform | None = None, **kwargs)¶
Extend the functionality of
matplotlib.text.Text
by allowing for text to be wrapped when a line reaches a certain width (in effect forming a text box). Private class.With this class, the user can specify the maximum width—in units of
widthcoords
—of a MatplotlibText
instance. If the addition of any character or word to a line would bring the length of that line beyond the maximum width, a new line will be inserted and that character or word will start the new line. The class does this by inhering frommatplotlib.text.Text
and overriding its_get_wrap_line_width()
method, ultimately creating a newmatplotlib.text.Text
artist. Besideswidth
andwidthcoords
, all arguments passed when instantiating this class (includingkwargs
) are passed tomatplotlib.text.Text
.(This implementation comes from a Github Gist posted by user “dneuman”. Link to Gist.)
- Parameters:
x (float, optional) – The x-coordinate of the text. All subsequent code in this module converts this number to an Axes-relative coordinate (instead of the default transData) by passing
transform=ax.transAxes
to the constructor., defaults to 0y (float, optional) – The y-coordinate of the text. All subsequent code in this module converts this number to an Axes-relative coordinate (instead of the default transData) by passing
transform=ax.transAxes
to the constructor., defaults to 0text (str, optional) – The text string to display, defaults to “”
width (float, optional) – The maximum allowable width of the text to be displayed. Beyond this maximum width, the text is wrapped and a new line is started., defaults to 0
widthcoords (
mpl.transforms.Transform
or None, optional) – The coordinate system ofwidth
, defaults to None (which is interpreted downstream in units of screen pixels)
- __init__(x: float = 0, y: float = 0, text: str = '', width: float = 0, widthcoords: Transform | None = None, **kwargs) None ¶
Initialize an instance of
_WrapText
at coordinatesx
,y
with stringtext
, with a maximum width ofwidth
expressed in units ofwidthcoords
.Besides
width
andwidthcoords
, all arguments (includingkwargs
) of this class are passed tomatplotlib.text.Text
.- Parameters:
x (float, optional) – The x-coordinate of the text. All subsequent code in this module converts this number to an Axes-relative coordinate (instead of the default transData) by passing
transform=ax.transAxes
to the constructor., defaults to 0y (float, optional) – The y-coordinate of the text. All subsequent code in this module converts this number to an Axes-relative coordinate (instead of the default transData) by passing
transform=ax.transAxes
to the constructor., defaults to 0text (str, optional) – The text string to display, defaults to “”
width (float, optional) – The maximum allowable width of the text to be displayed. Beyond this maximum width, the text is wrapped and a new line is started., defaults to 0
widthcoords (
matplotlib.transforms.Transform
or None, optional) – The coordinate system ofwidth
, defaults to None (which is interpreted downstream in units of screen pixels)
- Returns:
None
- Return type:
NoneType
- _get_wrap_line_width() float ¶
Return the maximum allowable width of the
_WrapText
instance. Private method.This method overrides the one implemented by
matplotlib.text.Text
, which is what allows the text to be wrapped.- Returns:
The maximum allowable width of the
_WrapText
instance, beyond which the text is wrapped.- Return type:
float
- create_intro_cards._ceil_div(dividend: float, divisor: float) float ¶
Perform ceiling division using upside-down floor division, which avoids introducing floating-point error. Private function.
- Parameters:
dividend (float) – The dividend of the ceiling division operation
divisor (float) – The divisor of the ceiling division operation
- Returns:
The result of the ceiling division
- Return type:
float
- create_intro_cards._format_data_and_derive_full_names(df: DataFrame, first_name_col: str, last_name_col: str, photo_path_col: str) DataFrame ¶
Format DataFrame for Mathtext compatibility and create Full Name column. Private function.
This function replaces null values with empty strings, converts all values to strings, and trims whitespace. It also creates a “Full Name” column by combining the first and last name columns. Custom columns are formatted for Mathtext compatibility by removing forbidden characters (
~
,^
,\
) from column names, escaping special Mathtext characters (space,#
,$
,%
,_
,{
,}
) in column names, and escaping dollar signs ($
) in column values. Name-related and photo path columns retain their original column names.- Parameters:
df (pd.DataFrame) – DataFrame to process, containing individual records with their attributes
first_name_col (str) – Name of the column containing first names
last_name_col (str) – Name of the column containing last names
photo_path_col (str) – Name of the column containing photo file paths
- Returns:
Processed DataFrame with Mathtext-compatible formatting and Full Name column
- Return type:
pd.DataFrame