abc
This commit is contained in:
37
test.py
Normal file
37
test.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import csv
|
||||
import pandas as pd
|
||||
import _pickle as pkl
|
||||
|
||||
|
||||
def trans_csv_to_pickle(filename):
|
||||
df = pd.read_csv(filename)
|
||||
save_df = pd.DataFrame(columns=["features", "label"])
|
||||
d_index = list(df.columns).index('features')
|
||||
print(df)
|
||||
for i in range(len(df)):
|
||||
features = df.loc[i].features.replace("inf", str(100000000.0))
|
||||
try:
|
||||
features = eval(features)
|
||||
except NameError:
|
||||
print(features)
|
||||
inf = 1e10
|
||||
eval(features)
|
||||
print(features)
|
||||
continue
|
||||
for feature in features:
|
||||
if not isinstance(feature, float):
|
||||
print(features)
|
||||
print(feature)
|
||||
# print(df.loc[i].label, type(df.loc[i].label))
|
||||
save_df.loc[i] = [features, int(df.loc[i].label)]
|
||||
print(save_df)
|
||||
print(type(save_df.loc[0]['features']))
|
||||
save_df.to_csv(filename)
|
||||
pkl_name = filename.replace("csv", "pkl")
|
||||
f_pkl = open(pkl_name, "wb")
|
||||
pkl.dump(save_df, f_pkl)
|
||||
f_pkl.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
trans_csv_to_pickle("result/ow_doh_features.csv")
|
||||
Reference in New Issue
Block a user