implementing Pandas DataFrame's .apply() method returning unexpected NaNs
I'm working with an scenario with the `.apply()` method on my Pandas DataFrame where it's returning NaN values unexpectedly. I'm using Pandas version 1.5.0. I have a DataFrame with numeric and string columns, and I want to apply a custom function that adds a suffix to string values while returning the original numeric values unchanged. Here's the DataFrame I'm working with: ```python import pandas as pd data = { 'A': [1, 2, 3], 'B': ['apple', 'banana', 'cherry'], 'C': [4.0, None, 6.0] } df = pd.DataFrame(data) ``` I defined a function like this: ```python def add_suffix(value): if isinstance(value, str): return value + '_fruit' return value ``` When I apply this function to the DataFrame: ```python result_df = df.apply(add_suffix) ``` I expected `result_df` to have the following output: ``` A B C 0 1 apple_fruit 4.0 1 2 banana_fruit NaN 2 3 cherry_fruit 6.0 ``` However, I'm getting: ``` A B C 0 1 apple_fruit 4.0 1 2 NaN NaN 2 3 cherry_fruit 6.0 ``` It seems that the function is not being applied consistently. I've also tried using `applymap()` instead, but it throws an behavior because it requires a function that operates element-wise on the DataFrame. I'm not sure how to proceed or if there's a more efficient way to achieve what I'm trying to do. Any insights would be appreciated! What's the correct way to implement this?