python - How to correctly write out a TSV file from a series in Pandas? -


i have read manual here , saw this answer, not working:

>>> import pandas pd >>> import csv >>> pd.series([my_list]).to_csv('output.tsv',sep='\t',index=false,header=false, quoting=csv.quote_none)     traceback (most recent call last):       file "<stdin>", line 1, in <module>     typeerror: to_csv() got unexpected keyword argument 'quoting' 

without quoting argument, works.

pd.series([my_list]).to_csv('output.tsv',sep='\t',index=false,header=false) 

but incompatible intended usage.

to make things more confusing, when wrote out table way, there no quotes, , no errors:

my_dataframe.to_csv('output2.tsv',sep='\t', quoting=csv.quote_none) 

any idea going on?

the internal pandas implementation of series.to_csv() first converts series dataframe , calls dataframe.to_csv() method:

def to_csv(self, path, index=true, sep=",", na_rep='', float_format=none,            header=false, index_label=none, mode='w', nanrep=none,            encoding=none, date_format=none, decimal='.'):     """     write series comma-separated values (csv) file     ...     """     pandas.core.frame import dataframe     df = dataframe(self)     # result string if no path provided, otherwise none     result = df.to_csv(path, index=index, sep=sep, na_rep=na_rep,                        float_format=float_format, header=header,                        index_label=index_label, mode=mode, nanrep=nanrep,                        encoding=encoding, date_format=date_format,                        decimal=decimal)     if path none:         return result 

so can convert , have richer set of parameters:

pd.dataframe(your_series_obj).to_csv(..., quoting=csv.quote_none) 

or:

your_series_obj.to_frame().to_csv(..., quoting=csv.quote_none) 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -