我想將.dat
文件的數據集轉換爲csv
文件。數據格式的樣子,將.dat轉換爲python中的.csv
Each row begins with the sentiment score followed by the text associated with that rating.
我想要的有情感值(-1或1)有一列並審查對應的情感值有一個文本審查有專欄。
是我的嘗試到目前爲止
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
import csv
# read flash.dat to a list of lists
datContent = [i.strip().split() for i in open("train.dat").readlines()]
# write it as a new CSV file
with open("train.csv", "wb") as f:
writer = csv.writer(f)
writer.writerows(datContent)
def your_func(row):
return row['Sentiments']/row['Review']
columns_to_keep = ['Sentiments', 'Review']
dataframe = pd.read_csv("train.csv", usecols=columns_to_keep)
dataframe['new_column'] = dataframe.apply(your_func, axis=1)
print dataframe
產生的train.csv它在審查每一個字後的逗號樣本屏幕截圖。
那麼,你是如何學習熊貓的''''read_csv''',這是一個單線程。 – sascha
什麼是分數與文本的分數?空間或標籤? –
到目前爲止您嘗試過什麼? – Unni