嗨伙计们,我在绘制条形图时遇到此错误,我无法摆脱它,我已经尝试了qplot和ggplot,但仍然是同样的错误.
以下是我的代码
library(dplyr)
library(ggplot2)
#Investigate data further to build a machine learning model
data_country = data %>%
group_by(country) %>%
summarise(conversion_rate = mean(converted))
#Ist method
qplot(country, conversion_rate, data = data_country,geom = "bar", stat ="identity", fill = country)
#2nd method
ggplot(data_country)+aes(x=country,y = conversion_rate)+geom_bar()
Run Code Online (Sandbox Code Playgroud)
错误:
stat_count() must not be used with a y aesthetic
Run Code Online (Sandbox Code Playgroud)
data_country中的数据
country conversion_rate
<fctr> <dbl>
1 China 0.001331558
2 Germany 0.062428188
3 UK 0.052612025
4 US 0.037800687
Run Code Online (Sandbox Code Playgroud)
错误来自条形图而不是虚线图表.任何建议都会有很大帮助
嗨伙计们收到这个错误:
'Index' object has no attribute 'labels'
Run Code Online (Sandbox Code Playgroud)
回溯看起来像这样:
Traceback (most recent call last):
File "<ipython-input-23-e0f428cee427>", line 1, in <module>
df_top_f = k.groupby(['features'])['features'].count().unstack('features')
File "C:\Anaconda3\lib\site-packages\pandas\core\series.py", line 2061, in unstack
return unstack(self, level, fill_value)
File "C:\Anaconda3\lib\site-packages\pandas\core\reshape.py", line 405, in unstack
fill_value=fill_value)
File "C:\Anaconda3\lib\site-packages\pandas\core\reshape.py", line 90, in __init__
self.lift = 1 if -1 in self.index.labels[self.level] else 0
AttributeError: 'Index' object has no attribute 'labels'
Run Code Online (Sandbox Code Playgroud)
在运行以下代码时
df_top_f = df.groupby(['features'])['features'].count().unstack('features')
Run Code Online (Sandbox Code Playgroud)
df具有以下结构:
features
Ind
0 Doorman
1 Cats Allowed
2 Doorman
3 Cats Allowed
4 Dogs …Run Code Online (Sandbox Code Playgroud) 我正在研究postgres查询以从表中删除重复项.下表是动态生成的,我想编写一个select查询,如果第一行有重复值,它将删除记录.
该表看起来像这样
Ist col 2nd col
4 62
6 34
5 26
5 12
Run Code Online (Sandbox Code Playgroud)
我想写一个select查询,删除第3行或第4行.
我正在使用 python 的 xlsxwriter 包来格式化我通过 mysql 查询生成的 Excel 报告。
问题是 sql 生成的报告动态返回列,因此他们无法事先知道将返回多少列。我试图仅将边框设置为返回的列数。但到目前为止,我只能对列数(A:DC)进行硬编码。任何人都可以帮我解决这个问题,我正在使用以下查询-
worksheet = writer.sheets['Sheet1']
formater = workbook.add_format({'border':1})
worksheet.set_column('A:DC',15,formater)
writer.save()
Run Code Online (Sandbox Code Playgroud) 我第一次使用线程库是为了加快我的 SARIMAX 模型的训练时间。但代码不断失败并出现以下错误
Bad direction in the line search; refresh the lbfgs memory and restart the iteration.
This problem is unconstrained.
This problem is unconstrained.
This problem is unconstrained.
Run Code Online (Sandbox Code Playgroud)
以下是我的代码:
import numpy as np
import pandas as pd
from statsmodels.tsa.arima_model import ARIMA
import statsmodels.tsa.api as smt
from threading import Thread
def process_id(ndata):
train = ndata[0:-7]
test = ndata[len(train):]
try:
model = smt.SARIMAX(train.asfreq(freq='1d'), exog=None, order=(0, 1, 1), seasonal_order=(0, 1, 1, 7)).fit()
pred = model.get_forecast(len(test))
fcst = pred.predicted_mean
fcst.index = test.index
mapelist …Run Code Online (Sandbox Code Playgroud) 当我试图运行下面的代码时,我最初收到以下错误 -
Error:-the JSON object must be str, not 'bytes'
import urllib.request
import json
search = '230 boulder lane cottonwood az'
search = search.replace(' ','%20')
places_api_key = 'AIzaSyDou2Q9Doq2q2RWJWncglCIt0kwZ0jcR5c'
url = 'https://maps.googleapis.com/maps/api/place/textsearch/json?query='+search+'&key='+places_api_key
json_obj = urllib.request.urlopen(url)
data = json.load(json_obj)
for item in data ['results']:
print(item['formatted_address'])
print(item['types'])
Run Code Online (Sandbox Code Playgroud)
进行一些故障排除后的更改,如: -
json_obj = urllib.request.urlopen(url)
obj = json.load(json_obj)
data = json_obj .readall().decode('utf-8')
Error - 'HTTPResponse' object has no attribute 'decode'
Run Code Online (Sandbox Code Playgroud)
我收到上面的错误,我已经尝试了stackoverflow上的多个帖子似乎没什么用.我上传了整个工作代码,如果有人能让它工作,我将非常感激.我不明白的是,为什么同样的事情对别人而不是我有用.谢谢!
python ×3
arima ×1
bar-chart ×1
border ×1
dataframe ×1
excel ×1
ggplot2 ×1
json ×1
pandas ×1
postgresql ×1
python-3.4 ×1
r ×1
urllib ×1
xlsxwriter ×1