小编Jam*_*ray的帖子

CSV输出错误的顺序

我正在将一些数据输出到CSV文件,但由于某种原因,该方法会交替输出数据的方式.下面的代码是用于将对象输出到CSV文件的方法.

@staticmethod
def OutputCSV(csv_file):
    posts = ApplicationModel.ApplicationModel.getTwitterObjects()
    csv_columns = ['post','sentiment']
    with open(csv_file, 'w') as csvfile:
        writer = csv.writer(csvfile)
        writer.writerow(csv_columns)
        for TwitterObject.TwitterObject in posts:
            writer.writerow({
                TwitterObject.TwitterObject.post,
                TwitterObject.TwitterObject.sentiment
            })
Run Code Online (Sandbox Code Playgroud)

以下文本是输出的CSV文件中的示例.

post,sentiment

b'@Angel4Rubio @ehillm @Arsenal welcott been shit since he came to the league.',neg

pos,"b'Leicester closer to title, Arsenal held: Leicester City need just five points to complete a fairytale Premier ... '"

pos,"b'Leicester closer to title, Arsenal held: Leicester City need just five points to complete a fairytale Premier ... '"

pos,"b' …
Run Code Online (Sandbox Code Playgroud)

python csv

1
推荐指数
1
解决办法
460
查看次数

标签 统计

csv ×1

python ×1