UnitIV 1
UnitIV 1
suitable examples
In Pandas, combining datasets is a common operation to manipulate and analyze data
effectively. Operations like Concat, Append, Merge, and Join allow us to work with multiple DataFrames.
Below is a detailed discussion with examples for each operation.
Combining datasets operations in pandas: concat, append, merge, and join. Each of these
functions has its use cases and methods of combining dataframes.
1. Concatenation
The pd.concat() function is used to concatenate DataFrames along a particular axis (row-wise or column-
wise).
Key Points:
Example:
import pandas as pd
# Sample DataFrames
print(result)
Output:
A B
0 1 3
1 2 4
0 5 7
1 6 8
2. Append
Key Points:
Example:
print(result)
Output:
A B
0 1 3
1 2 4
2 5 7
3 6 8
3. Merge
The pd.merge() function is used to combine DataFrames based on keys (like SQL joins).
Key Points:
Example:
# Sample DataFrames
print(result)
Output:
ID Name Score
0 2 Bob 85
4. Join
The DataFrame.join() method is used to combine DataFrames on their index or on a key column.
Key Points:
Example:
# Sample DataFrames
# Joining on index
print(result)
Output:
markdown
Name Score
2 Bob 85