Repository: databricks/koalas

Issue:
Can't use Spark's .alias() to rename column
I would like to rename a column using .alias() instead of the pandas syntax (it's cleaner in this case), but I get the error message seen below. .toDF() works for renaming all the columns. Can we implement .alias() please?
<img width="1542" alt="Screen Shot 2019-04-22 at 7 47 50 AM" src="https://user-images.githubusercontent.com/6416014/56506875-95c3eb00-64d4-11e9-8ca9-b7c7a198cfa1.png">



Discussion:
@brookewenig 
You can use spark methods like this : 
```python
from databricks import koalas
import pandas as pd 

df = pd.DataFrame(
    {'a': [4, 2, 3, 4, 8, 6], 'b': [1, 2, 9, 4, 2, 4],
     'c': ["one", "three", "six", "seven", "one", "5"]},
    index=[10, 20, 30, 40, 50, 60])

ddf = koalas.from_pandas(df)

ddf = ddf._spark_select(ddf.a.alias("e"))
print(ddf.show())
```
```
+---+
|  e|
+---+
|  4|
|  2|
|  3|
|  4|
|  8|
|  6|
+---+
```
@garawalid I find it confusing that some Spark methods work (like .toDF), but not others.
@brookewenig 
I agree it's a little bit confusing.  

Some Spark methods still work like `toDF` and `toPandas()`, but methods applied to a Spark DataFrame should start with `_spark_` like `ddf._spark_select()`

The idea behind Koalas is to create an API like Pandas. So, we expect users to use Pandas methods not Spark methods.
Hi,

If koalas is like pands, then how come the "rename" function doesn't work on koalas dataframe?

I tried to do ks_df.rename(), and I get the following error:

PandasNotImplementedError: The method `pd.DataFrame.rename()` is not implemented yet.

@GeorgeEatsData2018 
Koalas is under development, we will add the `rename` method soon. 
You can find implemented methods in the [documentation](https://koalas.readthedocs.io/en/latest/)
> @GeorgeEatsData2018
> Koalas is under development, we will add the `rename` method soon.
> You can find implemented methods in the [documentation](https://koalas.readthedocs.io/en/latest/)

Ok, thanks for letting me know. When koalas was introduced last week, I thought everything from pandas has been implemented to koalas. I will check the koalas documentation time to time.

Also, the head() method doesnt work on koalas dataframe. I tried doing koalas_df.head(), it returns
Out[21]: <databricks.koalas.frame.DataFrame at 0x7fa065580748>

Any idea how I can display the dataframe?


Thanks,
George
@GeorgeEatsData2018  You are welcome!

If you are using Jupyter notebook, it should work. Also,  calling `koalas_df` will display the dataframe. 

For adding `alias` into Koalas which only exists in Spark side, it's arguable. I think personally we should avoid adding Spark APIs into Koalas APIs but only Pandas corresponding APIs to avoid confusion and potential overhead to dev and users (see https://github.com/databricks/koalas/issues/139).

For `Serise`, seems working as @garawalid noted:

```python
>>> from databricks import koalas
>>> import pandas as pd
>>>
>>> df = pd.DataFrame(
...     {'a': [4, 2, 3, 4, 8, 6], 'b': [1, 2, 9, 4, 2, 4],
...      'c': ["one", "three", "six", "seven", "one", "5"]},
...     index=[10, 20, 30, 40, 50, 60])
>>>
>>> ddf = koalas.from_pandas(df)
>>> ddf.a.alias("e")
10    4
20    2
30    3
40    4
50    8
60    6
Name: e, dtype: int64
```

Resolving patch:
diff --git a/databricks/koalas/series.py b/databricks/koalas/series.py
--- a/databricks/koalas/series.py
+++ b/databricks/koalas/series.py
@@ -206,8 +206,8 @@ def getField(self, name):
                     "Field {} not found, possible values are {}".format(name, ", ".join(fnames)))
             return Series(self._scol.getField(name), self._kdf, self._index_info)
 
-    # TODO: automate the process here
     def alias(self, name):
+        """An alias for :meth:`Series.rename`."""
         return self.rename(name)
 
     @property
@@ -227,8 +227,39 @@ def name(self):
     def name(self, name):
         self.rename(name, inplace=True)
 
-    @derived_from(pd.Series)
+    # TODO: Functionality and documentation should be matched. Currently, changing index labels
+    # taking dictionary and function to change index are not supported.
     def rename(self, index=None, **kwargs):
+        """
+        Alter Series name.
+
+        Parameters
+        ----------
+        index : scalar
+            Scalar will alter the ``Series.name`` attribute.
+        inplace : bool, default False
+            Whether to return a new Series. If True then value of copy is
+            ignored.
+
+        Returns
+        -------
+        Series
+            Series with name altered.
+
+        Examples
+        --------
+        >>> s = ks.Series([1, 2, 3])
+        >>> s
+        0    1
+        1    2
+        2    3
+        Name: 0, dtype: int64
+        >>> s.rename("my_name")  # scalar, changes Series.name
+        0    1
+        1    2
+        2    3
+        Name: my_name, dtype: int64
+        """
         if index is None:
             return self
         scol = self._scol.alias(index)


Test patch: