-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdata_load.py
33 lines (26 loc) · 946 Bytes
/
data_load.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
33
# coding: utf-8
import pandas as pd
import tensorflow as tf
import os
import re
# Load all files from a directory in a DataFrame.
def load_dataset(directory):
data = pd.read_csv(directory)
data.rename(columns={'text':'sentence'}, inplace=True)
data['sentence'] = data['sentence'].astype(str)
data['sentiment'] = data['sentiment'].astype(str)
if "train" in directory:
data['selected_text'] = data['selected_text'].astype(str)
data['polarity'] = 0
data.loc[data['sentiment'] == 'negative', 'polarity'] = 1
data.loc[data['sentiment'] == 'positive', 'polarity'] = 2
if 'train' in directory:
data.drop(['textID'], axis=1, inplace=True)
else:
data.drop(['textID'], axis=1, inplace=True)
return data
if __name__ == "__main__":
train = load_dataset('./input_data/train.csv')
test = load_dataset('./input_data/test.csv')
print(train.head(10))
print(test.head(10))