title: Pandas apply based on column dtypes
body: <p>I have a sample dataframe on which I am trying to <code>apply</code> based on the column <code>dtype</code>:</p>
  <pre><code>df = pd.DataFrame(np.random.randint(0,10,size =(6,2)),columns=[&quot;A&quot;,&quot;B&quot;])
  df.loc[2,&quot;B&quot;]=np.NaN
  df[&quot;C&quot;]=np.NaN
  df[&quot;st&quot;]=[&quot;Mango&quot;]*6
  df[&quot;date&quot;]=[&quot;2001-01-01&quot;,&quot;2001-01-02&quot;,&quot;2001-01-03&quot;,&quot;2001-01-04&quot;,&quot;2001-01-05&quot;,&quot;2001-01-06&quot;]
  df[&quot;date&quot;]=pd.to_datetime(df[&quot;date&quot;])
  df
  </code></pre>
  <p>Sample dataframe:</p>
  <pre><code>    A    B   C  fruit     date
  0   1   1.0 NaN Mango   2001-01-01
  1   4   3.0 NaN Mango   2001-01-02
  2   8   NaN NaN Mango   2001-01-03
  3   2   1.0 NaN Mango   2001-01-04
  4   9   6.0 NaN Mango   2001-01-05
  5   9   6.0 NaN Mango   2001-01-06
  </code></pre>
  <p>I'm trying to transform the <code>DF</code> based on the column <code>dtypes</code> and generate a single <code>row</code>.</p>
  <p>pseudocode:</p>
  <pre><code>if data_type(column) == String:
     #first value in the column
     return column_value[0]
  
  if data_type(column) == datetime:
     #last value in the column
     return column_value[-1]
  
  if data_type(column) == int or data_type(column) == float:
     if all_values_in_column==np.NaN:
        return np.NaN
     else:
        #mean of the column
        return mean(column)
  </code></pre>
  <p>Code:</p>
  <pre><code>from pandas.api.types import is_datetime64_any_dtype as is_datetime
  from pandas.api.types import is_float,is_float_dtype,is_integer,is_integer_dtype
  
  def check(series):
     if is_string_dtype(series)==True:
         return series[0]
     elif is_datetime(series) == True:
         return series[len(series)-1]
     elif is_integer_dtype(series) ==True or is_float_dtype(series):
         if series.isnull().all()==True:
             return np.NaN
         else:
             return series.fillna(0).mean()
  
  op = pd.DataFrame(df.apply(check)).transpose()
  </code></pre>
  <p>Current output:</p>
  <pre><code>    A   B    C   st         date
  0   1   1   NaN Mango   2001-01-01 00:00:00
  </code></pre>
  <p>I am getting the wrong output, except for columns <code>C</code> and <code>st</code>.</p>
  <p>Expected output:</p>
  <pre><code>    A     B      C   st       date
  0   5.5 2.833   NaN Mango   2001-01-06 00:00:00
  </code></pre>
  <p>Any suggestions on the mistake could be helpful?</p>