Repository: pandas-dev/pandas

Issue:
Add option to hide index in pandas.Series.to_string
In the Dataframes.to_string function there is a option to not print the index:

index : bool, optional

```
whether to print index (row) labels, default True
```

Can this be added to the Series function to_string?

http://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.Series.to_string.html



Discussion:
sure that could be made consistent, pull-requests accepted.

Though in general this routine is mostly used internally.


Resolving patch:
diff --git a/pandas/core/format.py b/pandas/core/format.py
--- a/pandas/core/format.py
+++ b/pandas/core/format.py
@@ -126,14 +126,15 @@ def to_string(self):
 class SeriesFormatter(object):
 
     def __init__(self, series, buf=None, length=True, header=True,
-                 na_rep='NaN', name=False, float_format=None, dtype=True,
-                 max_rows=None):
+                 index=True, na_rep='NaN', name=False, float_format=None,
+                 dtype=True, max_rows=None):
         self.series = series
         self.buf = buf if buf is not None else StringIO()
         self.name = name
         self.na_rep = na_rep
         self.header = header
         self.length = length
+        self.index = index
         self.max_rows = max_rows
 
         if float_format is None:
@@ -241,7 +242,10 @@ def to_string(self):
             fmt_values.insert(row_num + n_header_rows, dot_str)
             fmt_index.insert(row_num + 1, '')
 
-        result = self.adj.adjoin(3, *[fmt_index[1:], fmt_values])
+        if self.index:
+            result = self.adj.adjoin(3, *[fmt_index[1:], fmt_values])
+        else:
+            result = self.adj.adjoin(3, fmt_values)
 
         if self.header and have_header:
             result = fmt_index[0] + '\n' + result
diff --git a/pandas/core/series.py b/pandas/core/series.py
--- a/pandas/core/series.py
+++ b/pandas/core/series.py
@@ -959,7 +959,7 @@ def __unicode__(self):
         return result
 
     def to_string(self, buf=None, na_rep='NaN', float_format=None, header=True,
-                  length=False, dtype=False, name=False, max_rows=None):
+                  index=True, length=False, dtype=False, name=False, max_rows=None):
         """
         Render a string representation of the Series
 
@@ -974,6 +974,8 @@ def to_string(self, buf=None, na_rep='NaN', float_format=None, header=True,
             default None
         header: boolean, default True
             Add the Series header (index name)
+        index : bool, optional
+            Add index (row) labels, default True
         length : boolean, default False
             Add the Series length
         dtype : boolean, default False
@@ -990,8 +992,8 @@ def to_string(self, buf=None, na_rep='NaN', float_format=None, header=True,
         """
 
         the_repr = self._get_repr(float_format=float_format, na_rep=na_rep,
-                                  header=header, length=length, dtype=dtype,
-                                  name=name, max_rows=max_rows)
+                                  header=header, index=index, length=length,
+                                  dtype=dtype, name=name, max_rows=max_rows)
 
         # catch contract violations
         if not isinstance(the_repr, compat.text_type):
@@ -1009,15 +1011,15 @@ def to_string(self, buf=None, na_rep='NaN', float_format=None, header=True,
                     f.write(the_repr)
 
     def _get_repr(
-        self, name=False, header=True, length=True, dtype=True, na_rep='NaN',
-            float_format=None, max_rows=None):
+        self, name=False, header=True, index=True, length=True, dtype=True,
+            na_rep='NaN', float_format=None, max_rows=None):
         """
 
         Internal function, should always return unicode string
         """
         formatter = fmt.SeriesFormatter(self, name=name,
                                         length=length, header=header,
-                                        dtype=dtype,
+                                        index=index, dtype=dtype,
                                         na_rep=na_rep,
                                         float_format=float_format,
                                         max_rows=max_rows)


Test patch:
diff --git a/pandas/tests/test_format.py b/pandas/tests/test_format.py
--- a/pandas/tests/test_format.py
+++ b/pandas/tests/test_format.py
@@ -3181,6 +3181,16 @@ def test_to_string_float_na_spacing(self):
                     '4       NaN')
         self.assertEqual(result, expected)
 
+    def test_to_string_without_index(self):
+        #GH 11729 Test index=False option
+        s= Series([1, 2, 3, 4])
+        result = s.to_string(index=False)
+        expected = (u(' 1\n') +
+                    ' 2\n' +
+                    ' 3\n' +
+                    ' 4')
+        self.assertEqual(result, expected)
+
     def test_unicode_name_in_footer(self):
         s = Series([1, 2], name=u('\u05e2\u05d1\u05e8\u05d9\u05ea'))
         sf = fmt.SeriesFormatter(s, name=u('\u05e2\u05d1\u05e8\u05d9\u05ea'))