@since(2.0)
@ignore_unicode_prefix
def createDataFrame(self, data, schema=None, samplingRatio=None, verifySchema=True):
    '\n        Creates a :class:`DataFrame` from an :class:`RDD`, a list or a :class:`pandas.DataFrame`.\n\n        When ``schema`` is a list of column names, the type of each column\n        will be inferred from ``data``.\n\n        When ``schema`` is ``None``, it will try to infer the schema (column names and types)\n        from ``data``, which should be an RDD of :class:`Row`,\n        or :class:`namedtuple`, or :class:`dict`.\n\n        When ``schema`` is :class:`pyspark.sql.types.DataType` or\n        :class:`pyspark.sql.types.StringType`, it must match the\n        real data, or an exception will be thrown at runtime. If the given schema is not\n        :class:`pyspark.sql.types.StructType`, it will be wrapped into a\n        :class:`pyspark.sql.types.StructType` as its only field, and the field name will be "value",\n        each record will also be wrapped into a tuple, which can be converted to row later.\n\n        If schema inference is needed, ``samplingRatio`` is used to determined the ratio of\n        rows used for schema inference. The first row will be used if ``samplingRatio`` is ``None``.\n\n        :param data: an RDD of any kind of SQL data representation(e.g. row, tuple, int, boolean,\n            etc.), or :class:`list`, or :class:`pandas.DataFrame`.\n        :param schema: a :class:`pyspark.sql.types.DataType` or a\n            :class:`pyspark.sql.types.StringType` or a list of\n            column names, default is ``None``.  The data type string format equals to\n            :class:`pyspark.sql.types.DataType.simpleString`, except that top level struct type can\n            omit the ``struct<>`` and atomic types use ``typeName()`` as their format, e.g. use\n            ``byte`` instead of ``tinyint`` for :class:`pyspark.sql.types.ByteType`. We can also use\n            ``int`` as a short name for ``IntegerType``.\n        :param samplingRatio: the sample ratio of rows used for inferring\n        :param verifySchema: verify data types of every row against schema.\n        :return: :class:`DataFrame`\n\n        .. versionchanged:: 2.0.1\n           Added verifySchema.\n\n        >>> l = [(\'Alice\', 1)]\n        >>> spark.createDataFrame(l).collect()\n        [Row(_1=u\'Alice\', _2=1)]\n        >>> spark.createDataFrame(l, [\'name\', \'age\']).collect()\n        [Row(name=u\'Alice\', age=1)]\n\n        >>> d = [{\'name\': \'Alice\', \'age\': 1}]\n        >>> spark.createDataFrame(d).collect()\n        [Row(age=1, name=u\'Alice\')]\n\n        >>> rdd = sc.parallelize(l)\n        >>> spark.createDataFrame(rdd).collect()\n        [Row(_1=u\'Alice\', _2=1)]\n        >>> df = spark.createDataFrame(rdd, [\'name\', \'age\'])\n        >>> df.collect()\n        [Row(name=u\'Alice\', age=1)]\n\n        >>> from pyspark.sql import Row\n        >>> Person = Row(\'name\', \'age\')\n        >>> person = rdd.map(lambda r: Person(*r))\n        >>> df2 = spark.createDataFrame(person)\n        >>> df2.collect()\n        [Row(name=u\'Alice\', age=1)]\n\n        >>> from pyspark.sql.types import *\n        >>> schema = StructType([\n        ...    StructField("name", StringType(), True),\n        ...    StructField("age", IntegerType(), True)])\n        >>> df3 = spark.createDataFrame(rdd, schema)\n        >>> df3.collect()\n        [Row(name=u\'Alice\', age=1)]\n\n        >>> spark.createDataFrame(df.toPandas()).collect()  # doctest: +SKIP\n        [Row(name=u\'Alice\', age=1)]\n        >>> spark.createDataFrame(pandas.DataFrame([[1, 2]])).collect()  # doctest: +SKIP\n        [Row(0=1, 1=2)]\n\n        >>> spark.createDataFrame(rdd, "a: string, b: int").collect()\n        [Row(a=u\'Alice\', b=1)]\n        >>> rdd = rdd.map(lambda row: row[1])\n        >>> spark.createDataFrame(rdd, "int").collect()\n        [Row(value=1)]\n        >>> spark.createDataFrame(rdd, "boolean").collect() # doctest: +IGNORE_EXCEPTION_DETAIL\n        Traceback (most recent call last):\n            ...\n        Py4JJavaError: ...\n        '
    if isinstance(data, DataFrame):
        raise TypeError('data is already a DataFrame')
    if isinstance(schema, basestring):
        schema = _parse_datatype_string(schema)
    try:
        import pandas
        has_pandas = True
    except Exception:
        has_pandas = False
    if (has_pandas and isinstance(data, pandas.DataFrame)):
        if (schema is None):
            schema = [str(x) for x in data.columns]
        data = [r.tolist() for r in data.to_records(index=False)]
    verify_func = (_verify_type if verifySchema else (lambda _, t: True))
    if isinstance(schema, StructType):

        def prepare(obj):
            verify_func(obj, schema)
            return obj
    elif isinstance(schema, DataType):
        dataType = schema
        schema = StructType().add('value', schema)

        def prepare(obj):
            verify_func(obj, dataType)
            return (obj,)
    else:
        if isinstance(schema, list):
            schema = [(x.encode('utf-8') if (not isinstance(x, str)) else x) for x in schema]
        prepare = (lambda obj: obj)
    if isinstance(data, RDD):
        (rdd, schema) = self._createFromRDD(data.map(prepare), schema, samplingRatio)
    else:
        (rdd, schema) = self._createFromLocal(map(prepare, data), schema)
    jrdd = self._jvm.SerDeUtil.toJavaArray(rdd._to_java_object_rdd())
    jdf = self._jsparkSession.applySchemaToPythonRDD(jrdd.rdd(), schema.json())
    df = DataFrame(jdf, self._wrapped)
    df._schema = schema
    return df
Creates a :class:`DataFrame` from an :class:`RDD`, a list or a :class:`pandas.DataFrame`.

When ``schema`` is a list of column names, the type of each column
will be inferred from ``data``.

When ``schema`` is ``None``, it will try to infer the schema (column names and types)
from ``data``, which should be an RDD of :class:`Row`,
or :class:`namedtuple`, or :class:`dict`.

When ``schema`` is :class:`pyspark.sql.types.DataType` or
:class:`pyspark.sql.types.StringType`, it must match the
real data, or an exception will be thrown at runtime. If the given schema is not
:class:`pyspark.sql.types.StructType`, it will be wrapped into a
:class:`pyspark.sql.types.StructType` as its only field, and the field name will be "value",
each record will also be wrapped into a tuple, which can be converted to row later.

If schema inference is needed, ``samplingRatio`` is used to determined the ratio of
rows used for schema inference. The first row will be used if ``samplingRatio`` is ``None``.

:param data: an RDD of any kind of SQL data representation(e.g. row, tuple, int, boolean,
    etc.), or :class:`list`, or :class:`pandas.DataFrame`.
:param schema: a :class:`pyspark.sql.types.DataType` or a
    :class:`pyspark.sql.types.StringType` or a list of
    column names, default is ``None``.  The data type string format equals to
    :class:`pyspark.sql.types.DataType.simpleString`, except that top level struct type can
    omit the ``struct<>`` and atomic types use ``typeName()`` as their format, e.g. use
    ``byte`` instead of ``tinyint`` for :class:`pyspark.sql.types.ByteType`. We can also use
    ``int`` as a short name for ``IntegerType``.
:param samplingRatio: the sample ratio of rows used for inferring
:param verifySchema: verify data types of every row against schema.
:return: :class:`DataFrame`

.. versionchanged:: 2.0.1
   Added verifySchema.

>>> l = [('Alice', 1)]
>>> spark.createDataFrame(l).collect()
[Row(_1=u'Alice', _2=1)]
>>> spark.createDataFrame(l, ['name', 'age']).collect()
[Row(name=u'Alice', age=1)]

>>> d = [{'name': 'Alice', 'age': 1}]
>>> spark.createDataFrame(d).collect()
[Row(age=1, name=u'Alice')]

>>> rdd = sc.parallelize(l)
>>> spark.createDataFrame(rdd).collect()
[Row(_1=u'Alice', _2=1)]
>>> df = spark.createDataFrame(rdd, ['name', 'age'])
>>> df.collect()
[Row(name=u'Alice', age=1)]

>>> from pyspark.sql import Row
>>> Person = Row('name', 'age')
>>> person = rdd.map(lambda r: Person(*r))
>>> df2 = spark.createDataFrame(person)
>>> df2.collect()
[Row(name=u'Alice', age=1)]

>>> from pyspark.sql.types import *
>>> schema = StructType([
...    StructField("name", StringType(), True),
...    StructField("age", IntegerType(), True)])
>>> df3 = spark.createDataFrame(rdd, schema)
>>> df3.collect()
[Row(name=u'Alice', age=1)]

>>> spark.createDataFrame(df.toPandas()).collect()  # doctest: +SKIP
[Row(name=u'Alice', age=1)]
>>> spark.createDataFrame(pandas.DataFrame([[1, 2]])).collect()  # doctest: +SKIP
[Row(0=1, 1=2)]

>>> spark.createDataFrame(rdd, "a: string, b: int").collect()
[Row(a=u'Alice', b=1)]
>>> rdd = rdd.map(lambda row: row[1])
>>> spark.createDataFrame(rdd, "int").collect()
[Row(value=1)]
>>> spark.createDataFrame(rdd, "boolean").collect() # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
    ...
Py4JJavaError: ...
@since(2.0)
@ignore_unicode_prefix
def createDataFrame(self, data, schema=None, samplingRatio=None, verifySchema=True):
    '\n        Creates a :class:`DataFrame` from an :class:`RDD`, a list or a :class:`pandas.DataFrame`.\n\n        When ``schema`` is a list of column names, the type of each column\n        will be inferred from ``data``.\n\n        When ``schema`` is ``None``, it will try to infer the schema (column names and types)\n        from ``data``, which should be an RDD of :class:`Row`,\n        or :class:`namedtuple`, or :class:`dict`.\n\n        When ``schema`` is :class:`pyspark.sql.types.DataType` or\n        :class:`pyspark.sql.types.StringType`, it must match the\n        real data, or an exception will be thrown at runtime. If the given schema is not\n        :class:`pyspark.sql.types.StructType`, it will be wrapped into a\n        :class:`pyspark.sql.types.StructType` as its only field, and the field name will be "value",\n        each record will also be wrapped into a tuple, which can be converted to row later.\n\n        If schema inference is needed, ``samplingRatio`` is used to determined the ratio of\n        rows used for schema inference. The first row will be used if ``samplingRatio`` is ``None``.\n\n        :param data: an RDD of any kind of SQL data representation(e.g. row, tuple, int, boolean,\n            etc.), or :class:`list`, or :class:`pandas.DataFrame`.\n        :param schema: a :class:`pyspark.sql.types.DataType` or a\n            :class:`pyspark.sql.types.StringType` or a list of\n            column names, default is ``None``.  The data type string format equals to\n            :class:`pyspark.sql.types.DataType.simpleString`, except that top level struct type can\n            omit the ``struct<>`` and atomic types use ``typeName()`` as their format, e.g. use\n            ``byte`` instead of ``tinyint`` for :class:`pyspark.sql.types.ByteType`. We can also use\n            ``int`` as a short name for ``IntegerType``.\n        :param samplingRatio: the sample ratio of rows used for inferring\n        :param verifySchema: verify data types of every row against schema.\n        :return: :class:`DataFrame`\n\n        .. versionchanged:: 2.0.1\n           Added verifySchema.\n\n        >>> l = [(\'Alice\', 1)]\n        >>> spark.createDataFrame(l).collect()\n        [Row(_1=u\'Alice\', _2=1)]\n        >>> spark.createDataFrame(l, [\'name\', \'age\']).collect()\n        [Row(name=u\'Alice\', age=1)]\n\n        >>> d = [{\'name\': \'Alice\', \'age\': 1}]\n        >>> spark.createDataFrame(d).collect()\n        [Row(age=1, name=u\'Alice\')]\n\n        >>> rdd = sc.parallelize(l)\n        >>> spark.createDataFrame(rdd).collect()\n        [Row(_1=u\'Alice\', _2=1)]\n        >>> df = spark.createDataFrame(rdd, [\'name\', \'age\'])\n        >>> df.collect()\n        [Row(name=u\'Alice\', age=1)]\n\n        >>> from pyspark.sql import Row\n        >>> Person = Row(\'name\', \'age\')\n        >>> person = rdd.map(lambda r: Person(*r))\n        >>> df2 = spark.createDataFrame(person)\n        >>> df2.collect()\n        [Row(name=u\'Alice\', age=1)]\n\n        >>> from pyspark.sql.types import *\n        >>> schema = StructType([\n        ...    StructField("name", StringType(), True),\n        ...    StructField("age", IntegerType(), True)])\n        >>> df3 = spark.createDataFrame(rdd, schema)\n        >>> df3.collect()\n        [Row(name=u\'Alice\', age=1)]\n\n        >>> spark.createDataFrame(df.toPandas()).collect()  # doctest: +SKIP\n        [Row(name=u\'Alice\', age=1)]\n        >>> spark.createDataFrame(pandas.DataFrame([[1, 2]])).collect()  # doctest: +SKIP\n        [Row(0=1, 1=2)]\n\n        >>> spark.createDataFrame(rdd, "a: string, b: int").collect()\n        [Row(a=u\'Alice\', b=1)]\n        >>> rdd = rdd.map(lambda row: row[1])\n        >>> spark.createDataFrame(rdd, "int").collect()\n        [Row(value=1)]\n        >>> spark.createDataFrame(rdd, "boolean").collect() # doctest: +IGNORE_EXCEPTION_DETAIL\n        Traceback (most recent call last):\n            ...\n        Py4JJavaError: ...\n        '
    if isinstance(data, DataFrame):
        raise TypeError('data is already a DataFrame')
    if isinstance(schema, basestring):
        schema = _parse_datatype_string(schema)
    try:
        import pandas
        has_pandas = True
    except Exception:
        has_pandas = False
    if (has_pandas and isinstance(data, pandas.DataFrame)):
        if (schema is None):
            schema = [str(x) for x in data.columns]
        data = [r.tolist() for r in data.to_records(index=False)]
    verify_func = (_verify_type if verifySchema else (lambda _, t: True))
    if isinstance(schema, StructType):

        def prepare(obj):
            verify_func(obj, schema)
            return obj
    elif isinstance(schema, DataType):
        dataType = schema
        schema = StructType().add('value', schema)

        def prepare(obj):
            verify_func(obj, dataType)
            return (obj,)
    else:
        if isinstance(schema, list):
            schema = [(x.encode('utf-8') if (not isinstance(x, str)) else x) for x in schema]
        prepare = (lambda obj: obj)
    if isinstance(data, RDD):
        (rdd, schema) = self._createFromRDD(data.map(prepare), schema, samplingRatio)
    else:
        (rdd, schema) = self._createFromLocal(map(prepare, data), schema)
    jrdd = self._jvm.SerDeUtil.toJavaArray(rdd._to_java_object_rdd())
    jdf = self._jsparkSession.applySchemaToPythonRDD(jrdd.rdd(), schema.json())
    df = DataFrame(jdf, self._wrapped)
    df._schema = schema
    return df