-
Notifications
You must be signed in to change notification settings - Fork 4
/
prepare.py
32 lines (25 loc) · 886 Bytes
/
prepare.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""Separate train and valid set for train file.
Author: Yixu GAO [email protected]
Usage:
python prepare.py --train_in 'data/SMP-CAIL2020-train.csv' \
--train_out 'data/train.csv' \
--valid_out 'data/valid.csv'
"""
import fire
import pandas as pd
def main(train_in='data/SMP-CAIL2020-train.csv',
train_out='data/train.csv',
valid_out='data/valid.csv'):
"""Main method to divide dataset.
Args:
train_in: origin train file
train_out: train file
valid_out: valid file
"""
data = pd.read_csv(train_in, encoding='utf-8')
total_num = data.shape[0]
train_num = int(0.8 * total_num)
data[:train_num].to_csv(train_out, encoding='utf-8', index=False)
data[train_num:].to_csv(valid_out, encoding='utf-8', index=False)
if __name__ == '__main__':
fire.Fire(main)