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 |
|
all_chars = True | False |
|
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)