pandas.DataFrame.append() function with example in python

Spread the love

pandas.DataFrame.append(): This function columns in other that are not in the caller are added as new columns.

Syntax: DataFrame.append(other, ignore_index=False, verify_integrity=False, sort=None)
Append rows of other to the end of caller, returning a new object.

Parameters:
other : DataFrame or Series/dict-like object, or list of these
The data to append.

ignore_index : boolean, default False
If True, do not use the index labels.

verify_integrity : boolean, default False
If True, raise ValueError on creating index with duplicates.

sort : boolean, default None
Sort columns if the columns of self and other are not aligned. The default sorting is deprecated and will change to not-sorting in a future version of pandas. Explicitly pass sort=True to silence the warning and sort. Explicitly pass sort=False to silence the warning and not sort.

Returns:
appended : DataFrame

import pandas as pd df1 = pd.DataFrame({'x': [1, 2, 2,3], 'y': [10,20,30,40]}) df2 = pd.DataFrame({'x': [4,5], 'y': [50,60]}) df1=df1.append(df2) print(df1)

Output:

 

Leave a Reply

Your email address will not be published. Required fields are marked *