小编use*_*568的帖子

Python:UnicodeDecodeError:'utf-8'编解码器无法解码位置35中的字节0x96:无效的起始字节

我是Python的新手,我正在尝试使用下面的脚本读取csv文件.

Past=pd.read_csv("C:/Users/Admin/Desktop/Python/Past.csv",encoding='utf-8')
Run Code Online (Sandbox Code Playgroud)

但是,得到错误"UnicodeDecodeError:'utf-8'编解码器无法解码位置35中的字节0x96:无效的起始字节",请帮我解决这里的问题,我在脚本中使用编码认为它会解决错误.

python csv pandas

8
推荐指数
6
解决办法
3万
查看次数

在python中读取SQL表

我正在尝试在 python 中读取 SQL 表。下面的脚本我正在使用并且能够正确读取数据。

Data = pd.read_sql_query("SELECT * from Data where [ID] = " + id ,engine)
Run Code Online (Sandbox Code Playgroud)

但是当列 ID 的类型更改为 nvarchar 时,出现以下错误。

DatabaseError: Execution failed on sql 'SELECT * from Data where [ID] = 123': ('42000', '[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Error converting data type nvarchar to numeric. (8114) (SQLExecDirectW)')
Run Code Online (Sandbox Code Playgroud)

有什么方法可以使用 nvarchar 列过滤表?

python sql type-conversion

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

使用 NLTK 提取单词词干 (python)

我是Python文本处理的新手,我正在尝试在文本文档中提取单词,大约有5000行。

我写了下面的脚本

from nltk.corpus import stopwords # Import the stop word list
from nltk.stem.snowball import SnowballStemmer

stemmer = SnowballStemmer('english')

def Description_to_words(raw_Description ):
    # 1. Remove HTML
    Description_text = BeautifulSoup(raw_Description).get_text() 
    # 2. Remove non-letters        
    letters_only = re.sub("[^a-zA-Z]", " ", Description_text) 
    # 3. Convert to lower case, split into individual words
    words = letters_only.lower().split()                       

    stops = set(stopwords.words("english"))                  
    # 5. Remove stop words
    meaningful_words = [w for w in words if not w in stops]   
    # 5. stem words
    words = ([stemmer.stem(w) for …
Run Code Online (Sandbox Code Playgroud)

python stemming

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

为 covectorizer 加载 pickle 文件

我有训练模型并保存了泡菜文件,但是当我尝试将它加载到新数据上时,我收到错误 >>> 回溯(最近一次调用):文件“”,第 1 行,在“

请参考下面的脚本,我在其中训练了数据保存的泡菜文件。

# Import the pandas package, then use the "read_csv" function to read
# the labeled training data
import os
import pandas as pd       
from bs4 import BeautifulSoup
import re
import nltk
from nltk.corpus import stopwords # Import the stop word list
from nltk.stem.snowball import SnowballStemmer
from nltk.tokenize import word_tokenize
from sklearn.feature_extraction.text import CountVectorizer
import numpy as np
from sklearn.ensemble import RandomForestClassifier
from sklearn.naive_bayes import MultinomialNB
from sklearn import svm
from sklearn.grid_search import GridSearchCV
import …
Run Code Online (Sandbox Code Playgroud)

python pickle training-data

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

阅读 Outlook 中的所有电子邮件

我想检查如何在 python 中阅读 Outlook 中的所有电子邮件

我正在使用以下代码,但此代码仅读取第一封邮件,

import win32com.client

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")

inbox = outlook.GetDefaultFolder(6) # "6" refers to the index of a folder - in this case,
                                    # the inbox. You can change that number to reference
                                    # any other folder
messages = inbox.Items
message = messages.GetLast()
body_content = message.Body
subject = message.Subject
categories = message.Categories
print(body_content)
print(subject)
print(categories)
Run Code Online (Sandbox Code Playgroud)

我试图找到一种方法,以便我们可以阅读所有电子邮件,但无法获得解决方案,有谁知道我们如何阅读所有电子邮件并将其存储在数据库中。

python outlook

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

标签 统计

python ×5

csv ×1

outlook ×1

pandas ×1

pickle ×1

sql ×1

stemming ×1

training-data ×1

type-conversion ×1