Pandas ConcatenationPandas is capable of combining Series, DataFrame, and Panel objects through different kinds of set logic for the indexes and the relational algebra functionality. The concat() function is responsible for performing concatenation operation along an axis in the DataFrame. Syntax:Parameters:
ReturnsA series is returned when we concatenate all the Series along the axis (axis=0). In case if objs contains at least one DataFrame, it returns a DataFrame. Example1:Output 0 p 1 q 0 r 1 s dtype: object Example2: In the above example, we can reset the existing index by using the ignore_index parameter. The below code demonstrates the working of ignore_index. Output 0 p 1 q 2 r 3 s dtype: object Example 3: We can add a hierarchical index at the outermost level of the data by using the keys parameter. Output a_data 0 p 1 q b_data 0 r 1 s dtype: object Example 4: We can label the index keys by using the names parameter. The below code shows the working of names parameter. Output Series name Row ID a_data 0 p 1 q b_data 0 r 1 s dtype: object Concatenation using appendThe append method is defined as a useful shortcut to concatenate the Series and DataFrame. Example: Output Name subject_id Marks_scored 1 Parker sub1 98 2 Smith sub2 90 3 Allen sub4 87 4 John sub6 69 5 Parker sub5 78 1 Billy sub2 89 2 Brian sub4 80 3 Bran sub3 79 4 Bryce sub6 97 5 Betty sub5 88 Next TopicPandas Data operations |