You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "nchammas (via GitHub)" <gi...@apache.org> on 2023/12/14 02:09:05 UTC

Re: [PR] [SPARK-45862][PYTHON][DOCS] Add user guide for basic dataframe operations [spark]

nchammas commented on code in PR #43972:
URL: https://github.com/apache/spark/pull/43972#discussion_r1426079059


##########
python/docs/source/user_guide/basic_dataframe_operations.rst:
##########
@@ -0,0 +1,169 @@
+..  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.
+
+==========================
+Basic DataFrame Operations
+==========================
+
+.. currentmodule:: pyspark.sql
+
+Select
+------
+
+Projects a set of expressions and returns a new :class:`DataFrame`.
+For more detailed usage methods, please refer to :meth:`DataFrame.select`.
+
+Select all columns
+~~~~~~~~~~~~~~~~~~
+
+.. code-block:: python
+
+    >>> df = spark.createDataFrame([(2, "Alice"), (5, "Bob")], schema=["age", "name"])

Review Comment:
   It's not a big deal, but note that the method you used here to specify the schema is not among the methods you demonstrated [over on #43897](https://github.com/apache/spark/pull/43897/files#diff-305f8ba2839b0d1db701f7c024c1c8fe3ec6d6e338dc2ba44a1d27780a361976R44).



##########
python/docs/source/user_guide/basic_dataframe_operations.rst:
##########
@@ -0,0 +1,169 @@
+..  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.
+
+==========================
+Basic DataFrame Operations
+==========================
+
+.. currentmodule:: pyspark.sql
+
+Select
+------
+
+Projects a set of expressions and returns a new :class:`DataFrame`.
+For more detailed usage methods, please refer to :meth:`DataFrame.select`.
+
+Select all columns
+~~~~~~~~~~~~~~~~~~
+
+.. code-block:: python
+
+    >>> df = spark.createDataFrame([(2, "Alice"), (5, "Bob")], schema=["age", "name"])
+    >>> df.select('*').show()
+    +---+-----+
+    |age| name|
+    +---+-----+
+    |  2|Alice|
+    |  5|  Bob|
+    +---+-----+
+
+
+Select by column names(string) or expressions (:class:`Column`)
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. code-block:: python
+
+    >>> df = spark.createDataFrame([(2, "Alice"), (5, "Bob")], schema=["age", "name"])
+    >>> df.select('name', (df.age + 10).alias('age')).show()

Review Comment:
   A minor point, but should we mention or demonstrate somehow that you can also select columns using the `__getitem__` syntax (`df["age"]`) in addition to the `__getattr__` syntax (`df.age`) demonstrated here?



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org