The Wayback Machine - https://web.archive.org/web/20240930163204/https://www.geeksforgeeks.org/python-pandas-index-append/
Open In App

Python | Pandas Index.append()

Last Updated : 24 Aug, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Python is an excellent language for data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas are one of those packages, making importing and analyzing data much easier.

Pandas Index.append() The function is used to append a single or a collection of indices together. In the case of a collection of indices, all of them get appended to the original index in the same order as they are passed to the Index.append() function. The function returns an appended index.

Syntax:
Index.append(other)

Parameters :
other : Index or list/tuple of indices

Returns : Index

Example 1: Use Index.append() function to append a single index to the given index.

Python3




# importing pandas as pd
import pandas as pd
 
# Creating the first Index
df1 = pd.Index([17, 69, 33, 5, 0, 74, 0])
 
# Creating the second Index
df2 = pd.Index([11, 16, 54, 58])
 
# Print the first and second Index
print(df1, "\n", df2)


Output :

Int64Index([17, 69, 33, 5, 0, 74, 0], dtype='int64') 
Int64Index([11, 16, 54, 58], dtype='int64')

Let’s append the df2 index at the end of df1.

Python3




# append df2 at the end of df1
df1.append(df2)


Output :

 Int64Index([17, 69, 33, 5, 0, 74, 0, 11, 16, 54, 58], dtype='int64')

As we can see in the output, the second index i.e. df2 has been appended at the end of df1 .  

Example 2: Use Index.append() function to append a collection of indexes at the end of the given index.

Python3




# importing pandas as pd
import pandas as pd
 
# Creating the first Index
df1 = pd.Index(['Jan', 'Feb', 'Mar', 'Apr'])
 
# Creating the second Index
df2 = pd.Index(['May', 'Jun', 'Jul', 'Aug'])
 
# Creating the third Index
df3 = pd.Index(['Sep', 'Oct', 'Nov', 'Dec'])
 
# Print the first, second and third Index
print(df1, "\n", df2, "\n", df3)


Output :

Index(['Jan', 'Feb', 'Mar', 'Apr'], dtype='object') 
Index(['May', 'Jun', 'Jul', 'Aug'], dtype='object')
Index(['Sep', 'Oct', 'Nov', 'Dec'], dtype='object')

Let’s append both the indexes df2 and df3 at the end of df1.

Python3




# We pass df2 and df3 as a list of
# indexes to the append function
df1.append([df2, df3])


Output :

Index(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct',
'Nov', 'Dec'],
dtype='object')


Previous Article
Next Article

Similar Reads

Python - Append List every Nth index
Given 2 list, append list to the original list every nth index. Input : test_list = [3, 7, 8, 2, 1, 5, 8], app_list = ['G', 'F', 'G'], N = 3 Output : ['G', 'F', 'G', 3, 7, 8, 'G', 'F', 'G', 2, 1, 5, 'G', 'F', 'G', 8] Explanation : List is added after every 3rd element.Input : test_list = [3, 7, 8, 2, 1, 5, 8, 9], app_list = ['G', 'F', 'G'], N = 4 O
5 min read
Python | Pandas TimedeltaIndex.append()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas TimedeltaIndex.append() function appends a collection of index options together. More than one index object can be appended at a
2 min read
Python | Pandas Series.append()
Pandas series is a One-dimensional ndarray with axis labels. The labels need not be unique but must be a hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index. Pandas Series.append() function is used to concatenate two or more series object. Syntax: Ser
4 min read
How to append a list as a row to a Pandas DataFrame in Python?
Prerequisite: Pandas DataFrame In this article, We are going to see how to append a list as a row to a pandas dataframe in Python. It can be done in three ways: Using loc[]Using iloc[]Using append()Append list using loc[] methods Pandas DataFrame.loc attribute access a group of rows and columns by label(s) or a boolean array in the given DataFrame.
3 min read
Append list of dictionary and series to a existing Pandas DataFrame in Python
In this article, we will discuss how values from a list of dictionaries or Pandas Series can be appended to an already existing pandas dataframe. For this purpose append() function of pandas, the module is sufficient. Syntax: DataFrame.append(other, ignore_index=False, verify_integrity=False, sort=None) Parameters :other : DataFrame or Series/dict-
2 min read
Python - Pandas dataframe.append()
Pandas append function is used to append rows of other data frames to the end of the given data frame, returning a new data frame object. Columns not in the original data frames are added as new columns and the new cells are populated with NaN value. Pandas dataframe append SyntaxSyntax: DataFrame.append(other, ignore_index=False, verify_integrity=
5 min read
Append data to an empty Pandas DataFrame
Let us see how to append data to an empty Pandas DataFrame. Creating the Data Frame and assigning the columns to it # importing the module import pandas as pd # creating the DataFrame of int and float a = [[1, 1.2], [2, 1.4], [3, 1.5], [4, 1.8]] t = pd.DataFrame(a, columns =["A", "B"]) # displaying the DataFrame print(t) print(t
2 min read
Pandas Append Rows & Columns to Empty DataFrame
Let’s discuss how to create an empty DataFrame and append rows & columns to it in Pandas and Python. There are multiple ways in which we can do this task. Here we will cover the following section: Creating an empty Dataframe in PandasAppend row to Dataframe in PandasAppend row to Dataframe in PandasCreating empty DataframeCreating an Empty Data
3 min read
How to Append Pandas DataFrame to Existing CSV File?
In this discussion, we'll explore the process of appending a Pandas DataFrame to an existing CSV file using Python. Add Pandas DataFrame to an Existing CSV File. To achieve this, we can utilize the to_csv() function in Pandas with the 'a' parameter to write the DataFrame to the CSV file in append mode. Pandas DataFrame to_csv() Syntax Syntax : df.t
3 min read
Python | Pandas Index.insert()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.insert() function make new Index inserting new item at location. This function also follows Python list.append() semantics
2 min read
Python | Pandas Index.get_slice_bound()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.get_slice_bound() function calculate slice bound that corresponds to given label and it returns the value. The function ret
2 min read
Python | Pandas Index.delete()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.delete() function returns a new object with the passed locations deleted. We can pass more than one locations to be deleted
2 min read
Python | Pandas Index.drop_duplicates()
Pandas Index.drop_duplicates() function return Index with duplicate values removed in Python. Syntax of Pandas Index.drop_duplicates() Syntax: Index.drop_duplicates(labels, errors='raise') Parameters : keep : {‘first’, ‘last’, False} ‘first’ : Drop duplicates except for the first occurrence.(default)‘last’ : Drop duplicates except for the last occu
2 min read
Python | Pandas Series.str.index()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas str.index() method is used to search and return lowest index of a substring in particular section (Between start and end) of ever
3 min read
Python | Pandas Index.dropna()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.dropna() function return Index without NA/NaN values. All the missing values are removed and a new object is returned which
2 min read
Python | Pandas Index.contains()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.contains() function return a boolean indicating whether the provided key is in the index. If the input value is present in
2 min read
Python | Pandas Series.nonzero() to get Index of all non zero values in a series
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Series.nonzero() is an argument less method. Just like it name says, rather returning non zero values from a series, it returns i
2 min read
Python | Pandas Index.difference()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.Pandas Index.difference() function return a new Index with elements from the index that are not in other. The function automatically sort
2 min read
Python | Pandas Index.any()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.any() function checks if any of the elements in the index are true or not. It returns one single boolean value if axis is n
2 min read
Python | Pandas Index.all()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.all() function checks if all the elements in the index are true or not. It returns one single boolean value if axis is not
2 min read
Python | Pandas Index.astype()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.astype() function create an Index with values cast to dtypes. The class of a new Index is determined by dtype. When convers
2 min read
Python | Pandas Index.asof()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.asof() function returns return the label from the index, or, if not present, the previous one. Assuming that the index is s
2 min read
Python | Pandas Index.argmin()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.argmin() function returns the indices of the minimum value present in the input Index. If we are having more than one minim
2 min read
Python | Pandas Index.argsort()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.argsort() function returns the integer indices that would sort the index. By default the sorting order has been set to incr
2 min read
Python | Pandas Index.argmax()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.argmax() function returns the indices of the maximum value present in the input Index. If we are having more than one maxim
2 min read
Python | Pandas Index.copy()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.copy() function make a copy of this object. The function also sets the name and dtype attribute of the new object as that o
2 min read
Python | Pandas Index.drop()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.drop() function make new Index with passed list of labels deleted. The function is similar to the Index.delete() except in
2 min read
Python | Pandas Index.equals()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.equals() function determine if two Index objects contains the same elements. If they contain the same elements then the fun
2 min read
Python | Pandas Index.max()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.max() function returns the maximum value of the Index. The function works with both numerical as well as the string type ob
2 min read
Python | Pandas Index.memory_usage()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.memory_usage() function return the memory usage of the Index. It returns the sum of the memory used by all the individual l
2 min read
Practice Tags :