Skip to content

Commit

Permalink
Update kaggle.save_sub
Browse files Browse the repository at this point in the history
  • Loading branch information
mxbi committed Jan 30, 2018
1 parent 4b19147 commit 6edc946
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,18 @@ Formats a duration in a pretty readable format, in terms of seconds, minutes, ho

### Kaggle

###### [mlcrate.kaggle.save_sub(df, filename='sub.csv.gz')](https://github.com/mxbi/mlcrate/blob/4cf3f95f557886d8fdf97e4a5ab0908edaa51332/mlcrate/kaggle.py#L1)
###### [mlcrate.kaggle.save_sub(df, filename='sub_{}.csv.gz')](https://github.com/mxbi/mlcrate/blob/4cf3f95f557886d8fdf97e4a5ab0908edaa51332/mlcrate/kaggle.py#L1)

Saves the passed dataframe with settings for a kaggle submission (index=False), and auto-enables GZIP compression if a '.gz' extension is passed.
Saves the passed dataframe with index=False, and enables GZIP compression if a '.gz' extension is passed.
If '{}' exists in the filename, this is replaced with the current time from mlcrate.time.now()

```python
>>> df
id probability
0 0 0.12
1 1 0.38
2 2 0.87
>>> mlc.kaggle.save_sub(df) # Saved as sub.csv.gz with compression
>>> mlc.kaggle.save_sub(df) # Saved as eg. sub_2017_12_28_16_58_29.csv.gz with compression
>>> mlc.kaggle.save_sub(df, 'sub_uncompressed.csv')
```

Expand Down
7 changes: 6 additions & 1 deletion mlcrate/kaggle.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
def save_sub(df, filename='sub.csv.gz'):
from . import time

def save_sub(df, filename='sub_{}.csv.gz'):
"""Saves the passed dataframe with index=False, and enables GZIP compression if a '.gz' extension is passed.
If '{}' exists in the filename, this is replaced with the current time from mlcrate.time.now()
Keyword arguments:
df -- The pandas DataFrame of the submission
filename -- The filename to save the submission to. Autodetects '.gz'
"""
if '{}' in filename:
filename = filename.format(time.now())
if filename.endswith('.gz'):
compression = 'gzip'
else:
Expand Down

0 comments on commit 6edc946

Please sign in to comment.