🏆 CONCAT & IGNORE INDEX | 🥇 Beats 93.48% | ✨ Most Efficient | ✔ Explained | Python | Pandas
Proof of 93.48%CodeDetailed Explanation

Importing the pandas library:
import pandas as pd
This line imports the pandas library, a powerful data manipulation an
# Proof of 93.48%
<!-- Describe your first thoughts on how to solve this problem. -->
![image.png](https://assets.leetcode.com/users/images/7c44e54d-1d38-4621-a73c-84090c01a878_1735735870.0157375.png)

# Code
```pythondata []
import pandas as pd

def concatenateTables(df1: pd.DataFrame, df2: pd.DataFrame) -> pd.DataFrame:
    con = pd.concat([df1, df2], ignore_index = True)
    return con
```

# Detailed Explanation
<!-- Describe your approach to solving the problem. -->

1. **Importing the pandas library:**
   ```python
   import pandas as pd
   ```
   This line imports the `pandas` library, a powerful data manipulation and analysis tool in Python, allowing for various operations on structured data, such as DataFrames.

2. **Defining the function `concatenateTables`:**
   ```python
   def concatenateTables(df1: pd.DataFrame, df2: pd.DataFrame) -> pd.DataFrame:
   ```
   This defines a function named `concatenateTables` that takes two arguments, `df1` and `df2`, both of which are expected to be pandas DataFrames. The function returns a pandas DataFrame.

3. **Concatenating the DataFrames:**
   ```python
   return pd.concat([df1, df2], ignore_index=True)
   ```
   - The `pd.concat` function concatenates the two DataFrames `df1` and `df2` along a particular axis (by default, along the rows). The result is a single DataFrame containing all rows from `df1` followed by all rows from `df2`.
   - The `ignore_index=True` parameter ensures that the index of the resulting DataFrame is reset, creating a new, continuous index starting from 0. Without this parameter, the original indices of `df1` and `df2` would be preserved, which might lead to duplicate indices.

**Example:**
Here's an example to illustrate how this function works:

```python
import pandas as pd

# Example DataFrames
data1 = {'A': [1, 2], 'B': [3, 4]}
data2 = {'A': [5, 6], 'B': [7, 8]}
df1 = pd.DataFrame(data1)
df2 = pd.DataFrame(data2)

# Before concatenation
print("DataFrame 1:")
print(df1)
print("\nDataFrame 2:")
print(df2)

# After concatenation
concatenated_df = concatenateTables(df1, df2)
print("\nConcatenated DataFrame:")
print(concatenated_df)
```

**Output:**
```
DataFrame 1:
   A  B
0  1  3
1  2  4

DataFrame 2:
   A  B
0  5  7
1  6  8

Concatenated DataFrame:
   A  B
0  1  3
1  2  4
2  5  7
3  6  8
```

In this example, the function `concatenateTables` takes two DataFrames `df1` and `df2` and combines them into a single DataFrame `concatenated_df`. The indices are reset to provide a continuous sequence from 0 to 3.


# Complexity
The time complexity of the provided code primarily depends on the size of the DataFrames being concatenated. Here is the breakdown:

1. **Concatenation Operation:**
   ```python
   con = pd.concat([df1, df2], ignore_index=True)
   ```
   The `pd.concat` function concatenates the two DataFrames `df1` and `df2` along the row axis (default behavior). The time complexity of this operation is \(O(n + m)\), where:
   - \(n\) is the number of rows in `df1`
   - \(m\) is the number of rows in `df2`

   This is because the function needs to copy all the elements from both DataFrames into the new concatenated DataFrame.

2. **Returning the Result:**
   ```python
   return con
   ```
   Returning the DataFrame `con` is an \(O(1)\) operation.

**Summary:**
- **Time Complexity:** \(O(n + m)\), where \(n\) is the number of rows in `df1` and \(m\) is the number of rows in `df2`.
- **Space Complexity:** \(O(n + m)\), as a new DataFrame is created to store the concatenated result.

This complexity is because the code needs to process and copy all the elements from both DataFrames to create the new combined DataFrame. 

![image.png](https://assets.leetcode.com/users/images/1dc03a4a-54da-4389-b299-d7bb2ecc9162_1735736120.3759272.png)


['Python3', 'Pandas']