From a7a53febe34926493203247dc497fc816af26a14 Mon Sep 17 00:00:00 2001 From: dandyrilla Date: Wed, 12 Jul 2023 01:18:41 +0900 Subject: [PATCH] Add a simpler way to do the same thing --- _posts/2017-08-14-pandas-tsv.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/_posts/2017-08-14-pandas-tsv.md b/_posts/2017-08-14-pandas-tsv.md index 90ad0d0..bf8e7f7 100644 --- a/_posts/2017-08-14-pandas-tsv.md +++ b/_posts/2017-08-14-pandas-tsv.md @@ -24,4 +24,15 @@ def to_tsv(df, filename, **kw): _kw = dict(sep='\t', index=False) _kw.update(kw) df.to_csv(filename, **_kw) +``` + + +```python +from functools import partial, partialmethod + +import pandas as pd + + +pd.read_tsv = partial(pd.read_csv, sep='\t', header=0) +pd.DataFrame.to_tsv = partialmethod(pd.DataFrame.to_csv, sep='\t', index=False) ``` \ No newline at end of file