我有一个包含域名的数据:
url var1
www.CNN.com xsd
www.Nbc.com wer
www.BBc.com xyz
www.fOX.com zyx
....
Run Code Online (Sandbox Code Playgroud)
数据属于Series类型.我使用以下内容将url变量转换为小写:
df.apply(lambda x: x.astype(str).str.lower())
Run Code Online (Sandbox Code Playgroud)
但是,它们保持不变.
我究竟做错了什么?
我正在使用R从这个站点 webscrape一个表.
我正在使用图书馆rvest.
#install.packages("rvest", dependencies = TRUE)
library(rvest)
OPMpage <- read_html("https://www.opm.gov/policy-data-oversight/data-analysis-documentation/federal-employment-reports/historical-tables/total-government-employment-since-1962/")
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
open.connection(x,"rb")出错:HTTP错误403.
我究竟做错了什么?
我有一个数据集,如下所示:
A B
1 aa 1234
2 ab 3456
3 bc [1357, 2468]
4 cc 8901
...
Run Code Online (Sandbox Code Playgroud)
我需要迭代 B 列,并将方括号 ([]) 中的所有值替换为括号中的左四位数字,因此数据集将如下所示:
A B
1 aa 1234
2 ab 3456
3 bc 1357
4 cc 8901
...
Run Code Online (Sandbox Code Playgroud)
我有这个代码:
for item in df['B']:
if len(item) > 4:
item_v = str(item[1:5])
df['B'][item] = item_v
print(df['B'][item])
Run Code Online (Sandbox Code Playgroud)
它会打印截断的值,但是,如果我检查 df 的头部,它仍然具有旧值:
> df['B'].head()
> A B
1 aa 1234
2 ab 3456
3 bc [1357, 2468]
4 cc 8901
...
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我有一个如下所示的列表:
var1 var2 count
A abc 4
A abc 3
A abc 2
A abc 1
A abc 1
B abc 7
B abc 5
B abc 2
B abc 1
B abc 1
C abc 4
C abc 3
C abc 2
C abc 1
C abc 1
....
Run Code Online (Sandbox Code Playgroud)
我想创建一个新的数据框,其中包含每组的前3个"计数"结果.它应该如下所示:
var1 var2 count
A abc 4
A abc 3
A abc 2
B abc 7
B abc 5
B abc 2
C abc 4
C abc 3
C abc …Run Code Online (Sandbox Code Playgroud) 我有一些由前端在 JQuery 中生成的数组。
Edit1(基于 Edgar Henriquez 的回答):
my_jq.js:
var a = ['one','two'];
var b = ['three','four'];
var c = ['five'];
var d = ['six','seven','eight'];
var e = ['nine','ten','eleven'];
var newArray = [];
//jsonify to send to the server
$.ajax('/output', {
type: "POST",
contentType: "application/json",
dataType: "json",
data: JSON.stringify(postData),
success: function(data, status){
console.log(newArray);
console.log(status);}
});
Run Code Online (Sandbox Code Playgroud)
我将选定的值传递给服务器(Flask/python)并让它计算笛卡尔积。然后我需要在 output.html 屏幕中显示输出
@app.route('/output', methods = ['GET','POST'])
def output():
data1 = request.get_json(force = True)
a = data1['a']
b = data1['b']
c = data1['c']
d = …Run Code Online (Sandbox Code Playgroud) 我有一个看起来像这样的系列:
col1 id
0 a 10
1 b 20
2 c 30
3 b 10
4 d 10
5 a 30
6 e 40
Run Code Online (Sandbox Code Playgroud)
我想要的输出是这样的:
a b c d e
10 1 1 0 1 0
20 0 1 0 0 0
30 1 0 1 0 0
40 0 0 0 0 1
Run Code Online (Sandbox Code Playgroud)
我得到了这段代码:
import pandas as pd
df['dummies'] = 1
df_ind.pivot(index='id', columns='col1', values='dummies')
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
137
138 if mask.sum() < len(self.index):
--> 139 raise ValueError('Index contains duplicate entries, ' …Run Code Online (Sandbox Code Playgroud) 我有一个页面,其复选框有字符串值(A,B,C).我正在尝试根据所选复选框的值创建一个在屏幕上构建字符串的应用程序,用'+'分隔,例如'A + B + C'或'A + B'等.
然而,当选中复选框时,我的div不显示.
我究竟做错了什么?
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
var arr = $(".offers:checked").map(function() {
return $(this).val();
}).get();
$('#displayConcatenatedString').html(arr.join('+'));
</script>
<div id="displayConcatenatedString"></div>
<table style="width:100%">
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
</tr>
<tr>
<td><label><input type="checkbox" name="selected" value="A" class="offers" />A</label></td>
<td><label><input type="checkbox" name="selected" value="B" class="offers" />B</label></td>
<td><label><input type="checkbox" name="selected" value="C" class="offers" />C</label></td>
</tr>
</table>Run Code Online (Sandbox Code Playgroud)
我正在为我的 Flask 应用程序构建一个群发电子邮件组件。
我使用过flask_mail,并且能够使用'smtp.google.com'作为服务器发送它:
app.config['MAIL_SERVER']='smtp.gmail.com'
Run Code Online (Sandbox Code Playgroud)
为了启用它,我必须在 Gmail 中禁用双向身份验证,并打开“不太安全的应用程序”的访问权限。
鉴于安全级别降低,此设置的安全性如何?
有更安全的替代方案吗?
我有一个字典列表l1,如下所示:
[{'A1': 'string',
'B1': {'ba': 'string',
'bb': 'string',
'bc': 'string',
'bd': 'string',
'be': 'string'},
'C1': {'ca': 'string',
'cb': [[[123,123],[123,123]]]},
'D1': 'string'},
...]
Run Code Online (Sandbox Code Playgroud)
某些字典(l1 元素)可能缺少一些键,例如,l1 的第二个列表元素可能没有'bc':''string'键/值对。
我需要将以下顶部和嵌套键/值元素提取到数据框中,如下所示:
bc bd cb D1
string string [[[123,123],[123,123]]] string
N/A string [[[123,123],[123,123]]] string
...
string N/A [[[123,123],[123,123]]] string
Run Code Online (Sandbox Code Playgroud)
我的代码如下:
temp_df = pd.DataFrame(columns = ['bc','bd','cb','D1']
for i in l1:
temp_df = temp_df.append({'bc': i.get(['B1']['bc'],'N/A'),
'bd': i.get(['B1']['bd'],'N/A'),
'cb': i.get(['C1']['cb'],'N/A'),
'D1': i.get(['D1'],'N/A')},
ignore_index=True)
Run Code Online (Sandbox Code Playgroud)
我收到的错误如下:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-113-543c6addad42> in <module>
1 …Run Code Online (Sandbox Code Playgroud) pandas ×5
python ×5
flask ×2
jquery ×2
string ×2
ajax ×1
arrays ×1
checkbox ×1
dictionary ×1
flask-mail ×1
gmail ×1
grouping ×1
html ×1
javascript ×1
json ×1
list ×1
lowercase ×1
nested ×1
pivot ×1
python-3.x ×1
r ×1
replace ×1
security ×1
transpose ×1
web-scraping ×1