Appending is vertically stacking one Dataframe below the other. This process enables creation of single Dataframe from two Dataframes. The number of columns in the two files shall ideally be same. Also the formats of the columns should be same. This will ensure proper stacking of the files. This article discusses steps to append 2 Dataframes in Python.
John has 2 month of transaction data. The 2 transactional data is of June and July month. Both the files has 6 columns available. The format of all the columns are consistent across both the Dataframes. He is looking forward to append them together to create single Panda Dataframe.
Below are the key steps to append two Dataframes together.
- Step 1: Import all the necessary modules in Python.
import pandas as pd
- Step 2: Use append function in Pandas to append files together. The second file can be added in the paranthesis. Please see the code below.
Trx_Data_2Months=Trx_Data_Jun20.append([Trx_Data_Jul20])
- Step 3: Check the ouput data quality. As the two files has 100 rows each, hence the output file shall have 200 rows.
Trx_Data_2Months.head(10) Print Shape of the file, i.e. number of rows and number of columns Trx_Data_2Months.shape
Thus, John is able to create single Dataframe as per his requirement in Python. The output Dataframe has 200 rows, as the two monthly Dataframe has 100 observation each.
To get top certifications in Python and build your resume visit here. Also, you can read books listed here to build strong knowledge around Python.
Visit us below for video tutorial:
Looking to practice more with this example? Drop us a note, we will email you the Code file:
📬 Stay Ahead in Data Science & AI – Subscribe to Newsletter!
- 🎯 Interview Series: Curated questions and answers for freshers and experienced candidates.
- 📊 Data Science for All: Simplified articles on key concepts, accessible to all levels.
- 🤖 Generative AI for All: Easy explanations on Generative AI trends transforming industries.
💡 Why Subscribe? Gain expert insights, stay ahead of trends, and prepare with confidence for your next interview.
👉 Subscribe here: