[SPARK-8535] [PYSPARK] PySpark : Can't create DataFrame from Pandas dataframe with no explicit column name
Because implicit name of `pandas.columns` are Int, but `StructField` json expect `String`. So I think `pandas.columns` are should be convert to `String`. ### issue * [SPARK-8535 PySpark : Can't create DataFrame from Pandas dataframe with no explicit column name](https://issues.apache.org/jira/browse/SPARK-8535) Author: x1- <viva008@gmail.com> Closes #7124 from x1-/SPARK-8535 and squashes the following commits: d68fd38 [x1-] modify unit-test using pandas. ea1897d [x1-] For implicit name of pandas.columns are Int, so should be convert to String.
This commit is contained in:
parent
f457569886
commit
b6e76edf30
|
@ -344,13 +344,15 @@ class SQLContext(object):
|
|||
|
||||
>>> sqlContext.createDataFrame(df.toPandas()).collect() # doctest: +SKIP
|
||||
[Row(name=u'Alice', age=1)]
|
||||
>>> sqlContext.createDataFrame(pandas.DataFrame([[1, 2]]).collect()) # doctest: +SKIP
|
||||
[Row(0=1, 1=2)]
|
||||
"""
|
||||
if isinstance(data, DataFrame):
|
||||
raise TypeError("data is already a DataFrame")
|
||||
|
||||
if has_pandas and isinstance(data, pandas.DataFrame):
|
||||
if schema is None:
|
||||
schema = list(data.columns)
|
||||
schema = [str(x) for x in data.columns]
|
||||
data = [r.tolist() for r in data.to_records(index=False)]
|
||||
|
||||
if not isinstance(data, RDD):
|
||||
|
|
Loading…
Reference in a new issue