@@ -5850,7 +5850,7 @@ def clip(self, a_min, a_max, out=None):
5850
5850
return clip (self , a_min , a_max , out )
5851
5851
5852
5852
@deprecate_kwarg ('transpose' , 'wide' )
5853
- def to_csv (self , filepath , sep = ',' , na_rep = '' , wide = True , dropna = None , dialect = 'default' , ** kwargs ):
5853
+ def to_csv (self , filepath , sep = ',' , na_rep = '' , wide = True , value_name = 'value' , dropna = None , dialect = 'default' , ** kwargs ):
5854
5854
"""
5855
5855
Writes array to a csv file.
5856
5856
@@ -5866,6 +5866,9 @@ def to_csv(self, filepath, sep=',', na_rep='', wide=True, dropna=None, dialect='
5866
5866
Whether or not writing arrays in "wide" format. If True, arrays are exported with the last axis
5867
5867
represented horizontally. If False, arrays are exported in "narrow" format: one column per axis plus one
5868
5868
value column. Defaults to True.
5869
+ value_name : str, optional
5870
+ Name of the column containing the values (last column) in the csv file when `wide=False` (see above).
5871
+ Defaults to 'value'.
5869
5872
dialect : 'default' | 'classic', optional
5870
5873
Whether or not to write the last axis name (using '\' ). Defaults to 'default'.
5871
5874
dropna : None, 'all', 'any' or True, optional
@@ -5890,7 +5893,15 @@ def to_csv(self, filepath, sep=',', na_rep='', wide=True, dropna=None, dialect='
5890
5893
>>> a.to_csv(fname, sep=';', wide=False)
5891
5894
>>> with open(fname) as f:
5892
5895
... print(f.read().strip())
5893
- nat;sex;0
5896
+ nat;sex;value
5897
+ BE;M;0
5898
+ BE;F;1
5899
+ FO;M;2
5900
+ FO;F;3
5901
+ >>> a.to_csv(fname, sep=';', wide=False, value_name='population')
5902
+ >>> with open(fname) as f:
5903
+ ... print(f.read().strip())
5904
+ nat;sex;population
5894
5905
BE;M;0
5895
5906
BE;F;1
5896
5907
FO;M;2
@@ -5907,7 +5918,7 @@ def to_csv(self, filepath, sep=',', na_rep='', wide=True, dropna=None, dialect='
5907
5918
frame = self .to_frame (fold , dropna )
5908
5919
frame .to_csv (filepath , sep = sep , na_rep = na_rep , ** kwargs )
5909
5920
else :
5910
- series = self .to_series (dropna = dropna is not None )
5921
+ series = self .to_series (value_name , dropna is not None )
5911
5922
series .to_csv (filepath , sep = sep , na_rep = na_rep , header = True , ** kwargs )
5912
5923
5913
5924
def to_hdf (self , filepath , key , * args , ** kwargs ):
@@ -5935,7 +5946,7 @@ def to_hdf(self, filepath, key, *args, **kwargs):
5935
5946
self .to_frame ().to_hdf (filepath , key , * args , ** kwargs )
5936
5947
5937
5948
def to_excel (self , filepath = None , sheet_name = None , position = 'A1' , overwrite_file = False , clear_sheet = False ,
5938
- header = True , transpose = False , wide = True , engine = None , * args , ** kwargs ):
5949
+ header = True , transpose = False , wide = True , value_name = 'value' , engine = None , * args , ** kwargs ):
5939
5950
"""
5940
5951
Writes array in the specified sheet of specified excel workbook.
5941
5952
@@ -5964,6 +5975,9 @@ def to_excel(self, filepath=None, sheet_name=None, position='A1', overwrite_file
5964
5975
Whether or not writing arrays in "wide" format. If True, arrays are exported with the last axis
5965
5976
represented horizontally. If False, arrays are exported in "narrow" format: one column per axis plus one
5966
5977
value column. Defaults to True.
5978
+ value_name : str, optional
5979
+ Name of the column containing the values (last column) in the Excel sheet when `wide=False` (see above).
5980
+ Defaults to 'value'.
5967
5981
engine : 'xlwings' | 'openpyxl' | 'xlsxwriter' | 'xlwt' | None, optional
5968
5982
Engine to use to make the output. If None (default), it will use 'xlwings' by default if the module is
5969
5983
installed and relies on Pandas default writer otherwise.
@@ -5985,7 +5999,7 @@ def to_excel(self, filepath=None, sheet_name=None, position='A1', overwrite_file
5985
5999
if wide :
5986
6000
pd_obj = self .to_frame (fold_last_axis_name = True )
5987
6001
else :
5988
- pd_obj = self .to_series ()
6002
+ pd_obj = self .to_series (value_name )
5989
6003
5990
6004
if engine is None :
5991
6005
engine = 'xlwings' if xw is not None else None
@@ -6021,8 +6035,8 @@ def to_excel(self, filepath=None, sheet_name=None, position='A1', overwrite_file
6021
6035
6022
6036
options = dict (header = header , index = header , transpose = transpose )
6023
6037
sheet [position ].options (** options ).value = pd_obj
6024
- # TODO: implement transpose via/in dump
6025
- # sheet[position] = self.dump(header=header, transpose=transpose )
6038
+ # TODO: implement wide via/in dump
6039
+ # sheet[position] = self.dump(header=header, wide=wide )
6026
6040
if close :
6027
6041
wb .save ()
6028
6042
wb .close ()
0 commit comments