我正在使用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')
顺便说一下,我正在使用德语文本。
答案 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:
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