itholic commented on code in PR #43897: URL: https://github.com/apache/spark/pull/43897#discussion_r1400324847
########## python/docs/source/user_guide/dataframe_creation.rst: ########## @@ -0,0 +1,179 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +================== +DataFrame creation +================== + +.. currentmodule:: pyspark.sql + +Basic data structures +--------------------- + +Pyspark provides an important class for handling data: Review Comment: Pyspark -> PySpark ########## python/docs/source/user_guide/dataframe_creation.rst: ########## @@ -0,0 +1,179 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +================== +DataFrame creation +================== + +.. currentmodule:: pyspark.sql + +Basic data structures +--------------------- + +Pyspark provides an important class for handling data: + +1. :class:`DataFrame`: a distributed collection of data grouped into named columns. + +Creating through `createDataFrame` +---------------------------------- + +A PySpark :class:`DataFrame` can be created via :meth:`SparkSession.createDataFrame` typically by passing +a list of lists, tuples, dictionaries and :class:`Row`, a pandas :class:`pandas.DataFrame` +and an :class:`pyspark.RDD` consisting of such a list. +:meth:`SparkSession.createDataFrame` takes the `schema` argument to specify the schema of the DataFrame. Review Comment: DataFrame -> :class:\`DataFrame\` ########## python/docs/source/user_guide/dataframe_creation.rst: ########## @@ -0,0 +1,179 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +================== +DataFrame creation +================== + +.. currentmodule:: pyspark.sql + +Basic data structures +--------------------- + +Pyspark provides an important class for handling data: + +1. :class:`DataFrame`: a distributed collection of data grouped into named columns. + +Creating through `createDataFrame` +---------------------------------- + +A PySpark :class:`DataFrame` can be created via :meth:`SparkSession.createDataFrame` typically by passing +a list of lists, tuples, dictionaries and :class:`Row`, a pandas :class:`pandas.DataFrame` +and an :class:`pyspark.RDD` consisting of such a list. +:meth:`SparkSession.createDataFrame` takes the `schema` argument to specify the schema of the DataFrame. +When it is omitted, PySpark infers the corresponding schema by taking a sample from the data. + +Creating a PySpark :class:`DataFrame` from a list of lists +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: python + + df = spark.createDataFrame([['Alice', 1], ['Bob', 5]]) + df + +DataFrame[_1: string, _2: bigint] + + +Creating a PySpark :class:`DataFrame` from a list of tuples +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: python + + df = spark.createDataFrame([('Alice', 1), ('Bob', 5)]) + df + +DataFrame[_1: string, _2: bigint] + + +Creating a PySpark :class:`DataFrame` from a list of dictionaries +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: python + + df = spark.createDataFrame([{'name': 'Alice', 'age': 1}]) + df + +DataFrame[age: bigint, name: string] + + +Creating a PySpark :class:`DataFrame` from a list of :class:`Row` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: python + + from pyspark.sql import Row + Person = Row('name', 'age') + df = spark.createDataFrame([Person("Alice", 1), Person("Bob", 5)]) + df + +DataFrame[name: string, age: bigint] + + +Creating a PySpark :class:`DataFrame` from a :class:`pandas.DataFrame` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: python + + import pandas as pd + df = spark.createDataFrame(pd.DataFrame([[1, 2]])) + df + +DataFrame[0: bigint, 1: bigint] + + +Creating a PySpark :class:`DataFrame` from a :class:`numpy.ndarray` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: python + + import numpy as np + import pandas as pd + df = spark.createDataFrame(pd.DataFrame(data=np.array([[1, 2], [3, 4]]), columns=['a', 'b'])) + df + +DataFrame[a: bigint, b: bigint] + + +Creating a PySpark :class:`DataFrame` from an :class:`pyspark.RDD` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: python Review Comment: > I think we'd better not mention RDD since it is not supported on connect +1, or at least we should add a note. ########## python/docs/source/user_guide/dataframe_creation.rst: ########## @@ -0,0 +1,179 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +================== +DataFrame creation +================== + +.. currentmodule:: pyspark.sql + +Basic data structures +--------------------- + +Pyspark provides an important class for handling data: + +1. :class:`DataFrame`: a distributed collection of data grouped into named columns. + +Creating through `createDataFrame` +---------------------------------- + +A PySpark :class:`DataFrame` can be created via :meth:`SparkSession.createDataFrame` typically by passing +a list of lists, tuples, dictionaries and :class:`Row`, a pandas :class:`pandas.DataFrame` +and an :class:`pyspark.RDD` consisting of such a list. Review Comment: Maybe do we want to mention :class:\`numpy.ndarray\` here as well? e.g. ```suggestion A PySpark :class:`DataFrame` can be created via :meth:`SparkSession.createDataFrame` typically by passing a list of lists, tuples, dictionaries, :class:`Row`, a pandas :class:`pandas.DataFrame`, a NumPy :class:\`numpy.ndarray\` and an :class:`pyspark.RDD`. ``` ########## python/docs/source/user_guide/dataframe_creation.rst: ########## @@ -0,0 +1,179 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +================== +DataFrame creation Review Comment: Maybe shall we capitalizing the first word of the title/sub-title for consistency with other documents? e.g. DataFrame Creation / Basic Data Structures ... ########## python/docs/source/user_guide/dataframe_creation.rst: ########## @@ -0,0 +1,179 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + +.. http://www.apache.org/licenses/LICENSE-2.0 + +.. Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +================== +DataFrame creation Review Comment: Maybe shall we capitalizing the first word of the title/sub-title for consistency with other documents? e.g. DataFrame Creation / Basic Data Structures ... -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
