i dont want it to ignore the zero in between the numbers of the two columns
时间: 2024-04-12 10:29:45 浏览: 29
If you don't want to ignore the zero in between the numbers of the two columns when merging, you can use the `apply` function along with a lambda function to concatenate the values as strings. Here's an example:
```python
import pandas as pd
# Create an example DataFrame
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
# Merge the two columns with zero in between
df['C'] = df.apply(lambda row: str(row['A']) + '0' + str(row['B']), axis=1)
print(df)
```
Output:
```
A B C
0 1 4 104
1 2 5 205
2 3 6 306
```
In the above code, we use `apply` along with a lambda function to concatenate the values of columns `A` and `B`. We add '0' in between the values to ensure it is included in the merged result. The `axis=1` parameter is used to apply the lambda function row-wise.
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)