def to_dataframe(d, **kw):
    '''
    to_dataframe(d) attempts to coerce the object d to a pandas DataFrame object. If d is a
      tuple of 2 items whose second argument is a dictionary, then the dictionary will be taken
      as arguments for the dataframe constructor. These arguments may alternately be given as
      standard keyword arguments.
    '''
    import pandas
    if pimms.is_itable(d): d = d.dataframe
    if is_dataframe(d): return d if len(kw) == 0 else pandas.DataFrame(d, **kw)
    if is_tuple(d) and len(d) == 2 and pimms.is_map(d[1]):
        try: return to_dataframe(d[0], **pimms.merge(d[1], kw))
        except Exception: pass
    # try various options:
    try: return pandas.DataFrame(d, **kw)
    except Exception: pass
    try: return pandas.DataFrame.from_records(d, **kw)
    except Exception: pass
    try: return pandas.DataFrame.from_dict(d, **kw)
    except Exception: pass
    raise ValueError('Coersion to dataframe failed for object %s' % d)
to_dataframe(d) attempts to coerce the object d to a pandas DataFrame object. If d is a
      tuple of 2 items whose second argument is a dictionary, then the dictionary will be taken
      as arguments for the dataframe constructor. These arguments may alternately be given as
      standard keyword arguments.