使用Python保存从Facebook收集的评论的最佳方法是什么?

时间:2016-07-11 15:32:54

标签: python facebook csv facebook-graph-api

我正在使用Python和Facebook-SDK从一些Facebook页面收集所有评论。

由于我想对这些评论进行情感分析,保存这些文本的最佳方法是什么,以便不需要对文本进行任何更改?

我现在将评论保存为表格,然后保存为CSV文件。

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Admin extends MY_Controller {

 public function index()
 {
    $this->load->view("layouts/header");
    $this->load->view("layouts/navbar");
    $this->load->view("just_organize/administrador/index");
    $this->load->view("layouts/footer");
 }
 public function day_s(){
    $time = date("H");
    $timezone = date("e");
    if ($time < "12") {
        $greeting= "Good morning";
    } else
    if ($time >= "12" && $time < "17") {
        $greeting= "Good afternoon";
    } else
    if ($time >= "17" && $time < "19") {
        $greeting= "Good evening";
    } else
    if ($time >= "19") {
        $greeting= "Good night";
    }
 }
}

但是如果我想读取这个保存的文件,我会收到以下错误:

table.to_csv('file-name.csv')

顺便说一下,我正在使用德语文本。

3 个答案:

答案 0 :(得分:2)

Have you tried this?

Set default encoder at the top of your code

import sys
reload(sys)
sys.setdefaultencoding("ISO-8859-1")

or

pd.read_csv('file-name.csv', encoding = "ISO-8859-1")

答案 1 :(得分:0)

如果你对数据的编码有所了解,你可以简单地使用pandas来读取你的csv,如下所示:

import pandas as pd
pd.read_csv('filename.csv', encoding='encoding')

答案 2 :(得分:0)

I would say it really depends on many different factors such as:

  • Size of the data
  • What kind of analysis, specifically, are you anticipating that you'll be doing
  • What format are you most comfortable working with the data

For most of my data munging in python I like to do it in pandas if possible, but sometimes that's not a feasible option given the size of the data. In that case you'd have to think about using something like pyspark. But here is a link to the pandas docs for reference, they have a lot of functionality for reading in all kinds of data: pandas docs