append() method

Combines rows from two or more dateframes into a single dataframe by appending one dateframe to the bottom of another dataframe.

Syntax

dataframe_1_name.append([dataframe_2_name, dataframe_3_name, ...n], common_columns_only = True|False, all_chars = True|False)

Parameters

Name Description
dataframe_2_name, dataframe_3_name, ...n

The dataframe or dataframes to append.

Dataframes are appended in the order in which you specify them. The output dataframe contains the rows from dataframe_1, followed by the rows from dataframe_2, and so on.

The source dataframes can have different or identical columns.

common_columns_only = True | False
  • True only those columns that are common to all dataframes being appended are included in the output dataframe.

    Dataframe columns are considered common if they have an identical name.

  • False all columns from all dataframes are included in the output dataframe. NaN values appear in the output dataframe where no column exists in the source dataframe.
all_chars = True | False
  • True converts all non-character columns in all dataframes being appended to the string data type.

    This global conversion to string data ensures that all identically named columns are appended without error.

  • False the data type of non-character columns in dataframes being appended remains unchanged.

Returns

HCL dataframe.

Examples

Append dataframes with identical data structures

You append the Trans_Jan, Trans_Feb, and Trans_Mar dataframes into a single dataframe called Trans_Q1 that includes all rows from the three source dataframes.

The source dataframes all have an identical set of columns so whether you specify True or False for common_columns_only does not matter.

Trans_Q1 = Trans_Jan.append([Trans_Feb, Trans_Mar], common_columns_only = False, all_chars = False)

Append dataframes with differing data structures

You have separate dataframes containing employee data from different divisions of a company. You need all the employee data in a single dataframe in order to perform some analysis. Most of the columns are the same across all the dataframes, but some columns not required for your analysis are unique to individual dataframes.

You use common_columns_only to specify that only columns that are the same across all dataframes are included in the output dataframe. If a column is not present in even one of the dataframes, it is omitted from the output.

Employees_All = Employees_HQ.append([Employees_West, Employees_South], common_columns_only = True, all_chars = False)