Question: I have a data frame that needs a column, `c3`, added. Each entry in the column depends on entries from the same row in two other columns, `c1` and `c2`. `c3` was originally created by mapping a function over pairs of entries in `c1` and `c2`. I'm trying to speed up the creation of `c3`, since there is a lot of data, by using `apply`. Here's what I have now:

```
frame['c3'] = frame.apply(lambda x: my_func(x[c1], x[c2],
                          extra_arg1, extra_arg2), axis=1). 

```

However, when I do this, 'c3' becomes a `float64`, while I need it to be of type `object` to preserve `None` values that I have for further processing of the dataframe (rather than having them converted to `NaN`, which is what happens with the given line of code, since the other values generated by the function are of type `int`). I know one can use `astype` to change the type of a column, but using it on the already-created column does not work - the `NaN` values remain as `NaN` values. Is there any way to tell `apply` that I want to preserve the `None` values? Do I need to do something special within the lambda expression or within `my_func`?

Answer: 
Pandas (at least in version 18.0) has a 

> 
> convert\_dtype : boolean, default True 
> 
> 
> Try to find better dtype for
>  elementwise function results. If False, leave as dtype=object
> 
> 
> 

```
a=pd.Series(['1','2','3',None])
a.apply(lambda x: int(x) if x is not None else None,convert_dtype=False)

Out[101]: 

0       1
1       2
2       3
3    None
dtype: object

```

the map function does not have a similar functionality
Your apply function is weird because you don't use `x`, instead you extract the two whole columns of your dataframe on each row.

I suggest you use the NaN and convert them to None after:

```
frame['c3'] = frame.apply(lambda row: my_func(row[c1], row[c2],
                      extra_arg1, extra_arg2), axis=1)

frame['c3'] = frame['c3'].where((pd.notnull(frame['c3'])), None)

```