我使用相同的预测变量组构建了一些不同的线性回归,如下所示:
model=LinearRegression()
model.fit(X=predictor_train,y=target_train)
prediction_train=model.predict(predictor_train)
pred=model.predict(main_frame.iloc[-1:,1:])
Run Code Online (Sandbox Code Playgroud)
为了创建目标变量的预测,我想Scikit算法用这些"预测变量"创建了一个方程.我的问题是:我如何获得这个等式?
我已经构建了一个示例代码,以查看事情是否按照我的意愿运行.
predictorgroups=predictor.groupby("sector")
targetco=target.iloc[1]
group=predictorgroups.get_group(targetco.sector).astype(object)
pdf=(group).sort('size',ascending=False)[:10].astype(object)
Run Code Online (Sandbox Code Playgroud)
它工作正常.所以我想升级并使代码交互多次,所以我将其改编为:
for i in range(len(target.index[:10])):
predictorgroups=predictor.groupby("sector")
targetco=target.iloc(i)
group=predictorgroups.get_group(targetco.sector).astype(object)
pdf=(group).sort('size',ascending=False)[:10].astype(object)
Run Code Online (Sandbox Code Playgroud)
请注意,这个代码与上面的代码完全相同.但是在第二个我得到这个错误:
Traceback (most recent call last):
File "/file.py", line 64, in <module>
group=predictorgroups.get_group(targetco.sector).astype(object)
AttributeError: '_iLocIndexer' object has no attribute 'sector'
Run Code Online (Sandbox Code Playgroud)
我注意到在第一个代码中,如果我打印,targetco我得到一个只有一个索引的Pandas系列.如果我在第二个中执行相同操作,则会得到以下对象类型:
targetco pandas.core.indexing._iLocIndexer object at 0x105a3e438
任何人都可以向我解释为什么会发生这种情况?为什么我在第二个代码中得到不同的响应,如果它们都是相同的?
我有一个数据帧:
df:
A B
id
3 'Yes' 23
5 'Yes' 67
6 'No' 56
8 'No' 23
Run Code Online (Sandbox Code Playgroud)
我有另一个数据帧:
calc:
A B
id
3 'No' 4
Run Code Online (Sandbox Code Playgroud)
我想用calc值更新df.我正在尝试使用以下内容:
tgsm.loc[i]=calc
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用.我一直收到以下错误:
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/core/indexing.py", line 693, in _align_series
raise ValueError('Incompatible indexer with Series')
ValueError: Incompatible indexer with Series
Run Code Online (Sandbox Code Playgroud)
如果尝试tgsm.loc[i]=calc[i],它会让我遇到另一个错误:
File "pandas/index.pyx", line 137, in pandas.index.IndexEngine.get_loc (pandas/index.c:4154)
File "pandas/index.pyx", line 159, in pandas.index.IndexEngine.get_loc (pandas/index.c:4018)
File "pandas/hashtable.pyx", line 675, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:12368)
File "pandas/hashtable.pyx", line 683, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:12322)
KeyError: 3
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助启发我的旅程吗?
我有这两个数据框:
df1:
Value
dude_id
123 x
543 y
984 z
df2:
Value
id
123 R
498 S
543 D
984 X
009 Z
Run Code Online (Sandbox Code Playgroud)
我想以df2一种只包含 的df1索引中存在的键的方式进行过滤。它应该看起来像这样:
df2:
Value
id
123 R
543 D
984 X
Run Code Online (Sandbox Code Playgroud)
我尝试了以下方法:
df2.filter(like=df.index, axis=0)
Run Code Online (Sandbox Code Playgroud)
然而,它使我出现以下错误:
ValueError: The truth value of a Int64Index is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Run Code Online (Sandbox Code Playgroud)
我缺少什么?
我正在使用此 API 来获取公司数据:https ://github.com/vkruoso/receita-tools
在这里你可以看到注册表是如何来到我这里的(看起来像一个json结构):https ://www.receitaws.com.br/v1/cnpj/27865757000102
我可以使用以下命令下载它:
cadastro = os.system("curl -X GET https://www.receitaws.com.br/v1/cnpj/27865757000102"
Run Code Online (Sandbox Code Playgroud)
如果我运行type(cadastro)它就会出现class 'int'在我面前。我想把它变成一个数据框。我怎么能这么做呢?
我有一个使用后缀'_o'的带有很多列的数据框。有没有办法删除标签末尾带有“ _o”的所有列?
在本文中,我看到了一种使用过滤器功能删除以某些内容开头的列的方法。但是,如何丢弃那些以某种结尾的东西呢?
我在 appscript 上创建了一个简单的代码,用于从 URL 中获取 Google Drive 文件名
function FileName (URL) {
var ss = SpreadsheetApp.openByUrl(URL);
return ss.getName();
}
Run Code Online (Sandbox Code Playgroud)
当我运行时出现错误:
例外:您无权调用 SpreadsheetApp.openByUrl。所需权限: https: //www.googleapis.com/auth/spreadsheets (linha 6)。
我已经在高级 Google 服务区域启用了 Drive 和 Sheets API,因此“https://www.googleapis.com/auth/spreadsheets”应该没问题,但事实并非如此。
我怎样才能做到这一点?
我在此链接中创建了一个示例表,其中包含问题复制。
我有一个DataFrame:
Actual Pred
Date
2005-04-01 10.2 10.364470
2005-05-01 9.4 9.542778
2005-06-01 9.5 9.684794
2005-07-01 9.4 9.547604
2005-08-01 9.7 9.768893
Run Code Online (Sandbox Code Playgroud)
我想为每个DataFrame的索引添加一个月,所以它看起来像这样:
Actual Pred
Date
2005-05-01 10.2 10.364470
2005-06-01 9.4 9.542778
2005-07-01 9.5 9.684794
2005-08-01 9.4 9.547604
2005-09-01 9.7 9.768893
Run Code Online (Sandbox Code Playgroud)
我怎么做?
重要评论:
当我命令print type(DataFrame.index[0])找出索引的数据类型时,我得到:
<class 'pandas.tslib.Timestamp'>
Run Code Online (Sandbox Code Playgroud)
只是为了让你知道这是一个熊猫时间戳.
我有两个数据帧我正在尝试合并:
target:
version city_id code
id
4 2 4 5736201000175
26 2 3 8290265000183
27 3 3 9529184000156
30 3 3 9263064000150
34 2 3 9312770000144
54 1 3 8407830000140
55 1 3 5590100000139
city:
federation_unit_id name
id
3 8 SAO PAULO
4 8 CAMPINAS
7 8 BARUERI
8 8 BEBEDOURO
9 8 SANTOS
Run Code Online (Sandbox Code Playgroud)
我想合并它们将target's"city_id"与city's"id" 合并在一起,最终数据框如下所示:
target:
version city_id code federation_unit_id name
id
4 2 4 5736201000175 8 CAMPINAS
26 2 3 8290265000183 8 SAO PAULO …Run Code Online (Sandbox Code Playgroud) 我有这个数据框:
person code year Height Size ...
0 73163529000108 2013 6.293900e+07 6.292900e+07
1 73163529000108 2012 5.206400e+07 5.282500e+07
2 73163529000108 2014 7.293900e+07 5.292900e+07
3 68402163000134 2013 3.225900e+07 2.389000e+06
4 68402163000134 2012 5.779300e+07 5.304800e+07
...
Run Code Online (Sandbox Code Playgroud)
我想包括一个“身高年增长”和“尺寸年增长”列,所以它看起来像这样:
person code year Height Height Y Growth Size ...
0 73163529000108 2013 6.293900e+07 0.2096 6.292900e+07
1 73163529000108 2012 5.206400e+07 5.282500e+07
2 73163529000108 2014 7.293900e+07 0,1589 5.292900e+07
3 68402163000134 2013 3.225900e+07 2.389000e+06
4 68402163000134 2012 5.779300e+07 -0.4419 5.304800e+07
...
Run Code Online (Sandbox Code Playgroud)
我不介意它出来的格式,我只需要它是可扩展的。我很难做到。有人可以提出替代方案吗?
我正在尝试为 Google 表格构建一个函数,以从 Google Places API 中的某些地方获取完整地址。
据我了解,为此我需要:
a) 在 Google Places API 上构建要拍摄的查询(例如:https : //maps.googleapis.com/maps/api/place/findplacefromtext/json? input = cordoaria% 20sao%20leopoldo%brasil & inputtype = textquery & key = AI ** *)
{
"candidates" : [
{
"place_id" : "ChIJ49bv_6lpGZURk4Hl8w31LRQ"
}
],
"debug_log" : {
"line" : []
},
"status" : "OK"
}
Run Code Online (Sandbox Code Playgroud)
b) 在 Google Places API 中执行该查询
c) 获取地点 id(它返回给我这个地点 id ChIJ49bv_6lpGZURk4Hl8w31LRQ)
d) 在 Google Places API 中再次搜索(例如:https : //maps.googleapis.com/maps/api/place/details/json? placeid = ChIJ49bv_6lpGZURk4Hl8w31LRQ & key = AI ****) …
我想检查一个单元格中是否有一个单词,但没有另一个。在这篇文章中,对此事有些热议,但是当选的解决方案包括一个脚本功能。必须有一种更简单的方法来做到这一点。
我想检查字符串“ investimentos”中是否存在字符串“ investimentos”而没有“ fundos”。
我已经尝试过以下方法:(免责声明:我是regex的初学者)
=regexmatch("investimentos";"(investimentos)^(fundos)")
=regexmatch("investimentos";"(investimentos).*^(fundos)")
=regexmatch("investimentos";"(investimentos)(^fundos)")
=regexmatch("investimentos";"(investimentos).*(^fundos)")
Run Code Online (Sandbox Code Playgroud)
我总是假的。有人可以在里面发光吗?
我有一列带有浮点数的值,我想将它们转换为整数。
pdsm:
federation_unit_id city_id
id
3 8.0 3.0
7 None None
17 8.0 3.0
18 8.0 3.0
19 8.0 9.0
Run Code Online (Sandbox Code Playgroud)
它们的类型是列中的值:class 'float',除了 None 是 NoneType。
如果我试试这个:
pdsm['federation_unit_id']=pdsm['federation_unit_id'].astype(int)
pdsm['city_id'].iloc[0]=pdsm.city_id.astype(int)
Run Code Online (Sandbox Code Playgroud)
我明白了:
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
Run Code Online (Sandbox Code Playgroud)
如果我试试这个:
pdsm['federation_unit_id']=pdsm['federation_unit_id'].apply(lambda x: x.astype(int) if x is not None else None)
pdsm['city_id'].iloc[0]=pdsm.city_id.apply(lambda x: x.astype(int) if x is not None else None)
Run Code Online (Sandbox Code Playgroud)
我得到:
AttributeError: 'float' object has no attribute 'astype'
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮忙吗?我要疯了。