小编Tol*_*oly的帖子

RemoveError: 'setuptools' 是 conda 的依赖项,无法从 conda 的运行环境中删除

我有赢 10

运行时:

conda update conda
Run Code Online (Sandbox Code Playgroud)

我遇到了这个错误:

RemoveError: 'setuptools' is a dependency of conda and cannot be removed from
conda's operating environment.
Run Code Online (Sandbox Code Playgroud)

似乎没什么帮助

我尝试卸载 anaconda 并收到一条成功消息,但似乎仍有一些旧版本的痕迹仍然存在

如何彻底清除 Anaconda 安装的所有痕迹?

python windows-installer setuptools anaconda conda

22
推荐指数
3
解决办法
2万
查看次数

选择最后n列并排除数据框中的最后n列

我如何能:

  1. 选择数据框中的最后3列并创建新数据框?

我试过了:

y = dataframe.iloc[:,-3:]
Run Code Online (Sandbox Code Playgroud)
  1. 排除最后3列并创建新数据框?

我试过了:

X = dataframe.iloc[:,:-3]
Run Code Online (Sandbox Code Playgroud)

它是否正确?

我在代码中进一步得到了数组维度错误,并希望确保此步骤正确无误.

谢谢

python indexing dataframe pandas object-slicing

12
推荐指数
2
解决办法
2万
查看次数

错误:random_sample()最多需要1个位置参数(给定2个)

我有random.sample函数的问题.这是代码:

import random
import numpy as np


simulateData = np.random.normal(30, 2, 10000)

meanValues = np.zeros(1000)

for i in range(1000):


    dRange = range(0, len(simulateData))
    randIndex = np.random.sample(dRange, 30)
    randIndex.sort()
    rand = [simulateData[j] for j in randIndex]
    meanValues[i] = rand.mean()
Run Code Online (Sandbox Code Playgroud)

这是错误:

TypeError                                 Traceback (most recent call last)
<ipython-input-368-92c8d9b7ecb0> in <module>()
 20 
 21     dRange = range(0, len(simulateData))
---> 22     randIndex = np.random.sample(dRange, 30)
 23     randIndex.sort()
 24     rand = [simulateData[i] for i in randIndex]

mtrand.pyx in mtrand.RandomState.random_sample   (numpy\random\mtrand\mtrand.c:10022)()

TypeError: random_sample() takes at most 1 …
Run Code Online (Sandbox Code Playgroud)

python random indexing numpy random-sample

6
推荐指数
2
解决办法
6650
查看次数

使用df.to_csv()编码错误

我试图将信息从Twits(screen_name,created_at和text)保存到pandas DataFrame中,然后将DataFrame保存为csv文件.

我收到编码错误

import tweepy
from tweepy import OAuthHandler

consumer_key = 'bla'
consumer_secret = 'bla'
access_token = 'bla'
access_secret = 'bla'
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
api = tweepy.API(auth)

import pandas as pd
import numpy as np
import datetime
import sys

encoding = sys.stdout.encoding or 'utf-8'
columns = ['Screen_Name', 'Time_Stamp', 'Tweet']
todays_date = datetime.datetime.now().date()
tweetDF = pd.DataFrame(columns=columns)

for tweet in tweepy.Cursor(api.search, q="manhattan", lang="en").items(10):
    lenDF = len(tweetDF)
    tweetDF.loc[lenDF] = [tweet.user.screen_name, tweet.created_at, tweet.text]

tweetDF.to_csv("C:/tweetDF")
Run Code Online (Sandbox Code Playgroud)

这里的错误:

UnicodeEncodeError                        Traceback (most recent call last) …
Run Code Online (Sandbox Code Playgroud)

python csv encoding utf-8 dataframe

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

ValueError:不支持连续多输出

我想在具有大约 5,000 行和 6 个特征的数据集上运行多种回归类型(Lasso、Ridge、ElasticNet 和 SVR)。线性回归。使用 GridSearchCV 进行交叉验证。代码很广泛,但这里有一些关键部分:

def splitTrainTestAdv(df):

    y = df.iloc[:,-5:]  # last 5 columns
    X = df.iloc[:,:-5]  # Except for last 5 columns


    #Scaling and Sampling

    X = StandardScaler().fit_transform(X)

    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.8, random_state=0)


return X_train, X_test, y_train, y_test

def performSVR(x_train, y_train, X_test, parameter):



    C = parameter[0]
    epsilon = parameter[1] 
    kernel = parameter[2]

    model = svm.SVR(C = C, epsilon = epsilon, kernel = kernel)
    model.fit(x_train, y_train)



return model.predict(X_test)  #prediction for the test …
Run Code Online (Sandbox Code Playgroud)

python linear-regression cross-validation

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

Python 中的 Prophet / fbprophet 包

有人能解释一下如何在 Python3 上安装 Prophet 吗?

我试过了,pip install fbprophet但没有用。

在导入 pandas 和 sklearn 后尝试在笔记本中执行此操作并出现另一个错误:

import pandas as pd
import sklearn as sk
from fbprophet import Prophet
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-4-f503e9c6cf11> in <module>()
----> 1 from fbprophet import Prophet

ModuleNotFoundError: No module named 'fbprophet'
Run Code Online (Sandbox Code Playgroud)

python installation facebook-prophet

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

Python 中时间序列的季节趋势黄土法

有谁知道是否有基于Python的程序利用STL(季节-趋势-黄土)方法分解时间序列?

我看到引用了一个包装程序来调用stlR 中的函数,但我发现从环境设置的角度来看(Python 和 R 一起)不稳定且麻烦。另外,链接已有 4 岁了。

有人可以指出一些最近的事情吗(例如sklearnspicy等等)?

python time-series loess stl-decomposition

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

使用Counter创建字典

我有一个单词的输出,我想用它来创建一个字典,其中keys = word; value =单词的频率

这是代码:

import pandas as pd
import numpy as np
import datetime
import sys
import codecs
import re
import urllib, urllib2

import nltk  # Natural Language Processing

from nltk.corpus import stopwords # list of words
import string  # list(string.punctuation) - produces a list of punctuations
from collections import Counter  # optimized way to do this

#wordToken = ['happy', 'thursday', 'from', 'my', 'big', 'sweater', 'and', 'this', 'ART', '@', 'East', 'Village', ',', 'Manhattan', 'https', ':', '//t.co/5k8PUInmqK', 'RT', '@', …
Run Code Online (Sandbox Code Playgroud)

python counter dictionary tokenize

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

如何为 Python 安装 SHAP (Shapley)

尝试使用安装 Shapley 包(R 中可用)

install shap
Run Code Online (Sandbox Code Playgroud)

但出现错误:

Building wheels for collected packages: shap, iml
Running setup.py bdist_wheel for shap ... error
Complete output from command C:\Users\Toly_Novik\Anaconda3\python.exe -u -c     "import setuptools, tokenize;__file__='C:\\Users\\TOLY_N~1\\AppData\\Local\\Temp  \\pip-install-o0p96nl3\\shap\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d C:\Users\TOLY_N~1\AppData\Local\Temp\pip-wheel-538qnmm2 --python-tag cp36:
running bdist_wheel
running build
running build_py
creating build
creating build\lib.win-amd64-3.6
creating build\lib.win-amd64-3.6\shap
copying shap\datasets.py -> build\lib.win-amd64-3.6\shap
copying shap\plots.py -> build\lib.win-amd64-3.6\shap
copying shap\__init__.py -> build\lib.win-amd64-3.6\shap
creating build\lib.win-amd64-3.6\shap\explainers
copying shap\explainers\ime.py -> build\lib.win-amd64-3.6\shap\explainers
copying shap\explainers\kernel.py -> build\lib.win-amd64-3.6\shap\explainers
copying shap\explainers\mimic.py -> build\lib.win-amd64-3.6\shap\explainers …
Run Code Online (Sandbox Code Playgroud)

python installation xgboost

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

ValueError:不支持连续

我使用GridSearchCV进行线性回归的交叉验证(不是分类器也不是逻辑回归).

我还使用StandardScaler来标准化X.

我的数据框有17个特征(X)和5个目标(y)(观察).大约1150行

我一直得到ValueError:不支持连续错误消息并且没有选项.

这里有一些代码(假设所有导入都正确完成):

soilM = pd.read_csv('C:/training.csv', index_col=0)
soilM = getDummiedSoilDepth(soilM) #transform text values in 0 and 1

soilM = soilM.drop('Depth', 1) 

soil = soilM.iloc[:,-22:]

X_train, X_test, Ca_train, Ca_test, P_train, P_test, pH_train, pH_test, SOC_train, SOC_test, Sand_train, Sand_test = splitTrainTestAdv(soil)

scores = ['precision', 'recall']


for score in scores:

    for model in MODELS.keys():

        print model, score

        performParameterSelection(model, score, X_test, Ca_test, X_train, Ca_train)

def performParameterSelection(model_name, criteria, X_test, y_test, X_train, y_train):

    model, param_grid = MODELS[model_name]
    gs = GridSearchCV(model, param_grid, n_jobs= 1, cv=5, verbose=1, …
Run Code Online (Sandbox Code Playgroud)

python linear-regression pandas scikit-learn grid-search

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

Anaconda Navigator 在 Mac 上无法启动

我有 MacPro(M1 芯片)Monterrey (12.2.1) 我尝试启动 Navigator 但出现错误。我以前从未遇到过这样的错误:

Navigator Error
An unexpected error occurred on Navigator start-up

Report
Please report this issue in the anaconda issue tracker

Main Error
failed to run: 'conda info --json': "FileNotFoundError(2, 'No such file or directory')"
Traceback
Traceback (most recent call last):
  File "/Users/tolynovik/opt/anaconda3/lib/python3.8/site-packages/anaconda_project/internal/conda_api.py", line 68, in _call_conda
    (p, stdout_lines, stderr_lines) = streaming_popen.popen(cmd_list,
  File "/Users/tolynovik/opt/anaconda3/lib/python3.8/site-packages/anaconda_project/internal/streaming_popen.py", line 83, in popen
    p = logged_subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)
  File "/Users/tolynovik/opt/anaconda3/lib/python3.8/site-packages/anaconda_project/internal/logged_subprocess.py", line 27, in Popen
    return subprocess.Popen(args=args, **kwargs)
  File "/Users/tolynovik/opt/anaconda3/lib/python3.8/subprocess.py", …
Run Code Online (Sandbox Code Playgroud)

navigator anaconda

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