我在让reducer与React上下文一起工作时遇到麻烦。在中buttonbar.js,有两个按钮应该用来更新状态。通过过滤当前数据来更新状态。单击按钮,我没有收到任何错误,但是它也没有执行任何操作。我认为问题出在减速器上。
context.js
import React, { useState, useEffect } from "react";
import * as moment from "moment";
import axios from "axios";
export const Context = React.createContext();
const url = "https://projects.fivethirtyeight.com/polls/polls.json";
export const filterReducer = (state, action) => {
switch (action.type) {
case "SHOW_ALL":
return state.polls;
case "SHOW_APPROVAL":
return state.polls.filter(e => e.type === "trump-approval");
default:
return state.polls;
}
};
export function Provider({ children }) {
let intialState = {
polls: [],
dispatch: action => this.setState(state => filterReducer(state, action)) …Run Code Online (Sandbox Code Playgroud) import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df = pd.read_csv("arrests.csv")
df = df.replace(np.nan,0)
df = df.groupby(['home_team'])['arrests'].mean()
Run Code Online (Sandbox Code Playgroud)
我正在尝试为数据框创建条形图.在home_team下面是一堆团队名称.在逮捕期间,每个日期都有一些逮捕.我基本上按团队的数据对这个团队的平均逮捕进行了分组.我正在尝试为此创建一个条形图,但我不确定如何继续,因为一列没有标题.
我想在一个uicollection视图上方放置一个搜索栏,如下图所示.我想以编程方式执行此操作.

目前来看
这是我的搜索栏设置功能代码.我在家庭视图控制器中有它.
func setupSearchBar() {
let searchBar = UISearchBar(frame: CGRect(x: 0, y: 64, width:UIScreen.main.bounds.width, height: 32))
searchBar.barTintColor = UIColor(red: 64/255, green: 64/255, blue: 64/255, alpha: 1)
searchBar.backgroundColor = UIColor.blue
searchBar.isTranslucent = true
searchBar.placeholder = "Search Timeline"
searchBar.searchBarStyle = UISearchBarStyle.prominent
view.addSubview(searchBar)
}
Run Code Online (Sandbox Code Playgroud) 我想删除包含字符串“第四季度结束”的行之后的所有行。目前,这是第 474 行,但它会根据游戏而变化。
from bs4 import BeautifulSoup
import requests
import pandas as pd
import re
url = "http://www.espn.com/nba/playbyplay?gameId=400900395"
r = requests.get(url)
data = r.text
soup = BeautifulSoup(data,"html.parser")
data_rows = soup.findAll("tr")[4:]
play_data = []
for i in range(len(data_rows)):
play_row = []
for td in data_rows[i].findAll('td'):
play_row.append(td.getText())
play_data.append(play_row)
df = pd.DataFrame(play_data)
df.to_html("pbp_data")
Run Code Online (Sandbox Code Playgroud) 我有一个包含 12 列数据的 CSV。我专注于这 4 列
现在我已经绘制了“Pass def”和“Rush def”。我希望能够突出散点图上的特定点。例如,我想在图中突出显示 1995 DAL 点并将该点更改为黄色。
我已经开始使用 for 循环,但我不知道该去哪里。任何帮助都会很棒。
这是我的代码:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import csv
import random
df = pd.read_csv('teamdef.csv')
x = df["Pass Def."]
y = df["Rush Def."]
z = df["Season"]
points = []
for point in df["Season"]:
if point == 2015.0:
print(point)
plt.figure(figsize=(19,10))
plt.scatter(x,y,facecolors='black',alpha=.55, s=100)
plt.xlim(-.6,.55)
plt.ylim(-.4,.25)
plt.xlabel("Pass DVOA")
plt.ylabel("Rush DVOA")
plt.title("Pass v. Rush DVOA")
plot.show
Run Code Online (Sandbox Code Playgroud) 当我选择表格视图上的单元格时,它会变为此白色.我想改变它.
我尝试使用if语句,但它没有用.
这是我使用的代码.
override func tableView(_ tableView: UITableView, cellForRowAt
indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellId", for: indexPath)
if cell.isSelected == true {
cell.backgroundColor = .blue
} else {
cell.backgroundColor = .red
}
return cell
}
Run Code Online (Sandbox Code Playgroud) 我有一个数据框,其中包含有玩家姓名和统计数据的列.我绘制了两个不同的统计数据,希望玩家名称出现在散点图上的每个点下面.
这是我到目前为止所做的,但它不起作用.对于文本,我假设这是我想要在图上每个点下面的名称列表,源是名称来自的位置.
p = Scatter(dt,x='off_rating',y='def_rating',title="Offensive vs. Defensive Eff",color="navy")
labels = LabelSet(x='off_rating',y='def_rating',text="player_name",source=dt)
p.add_layout(labels)
Run Code Online (Sandbox Code Playgroud) 我想突出显示 ggplot 散点图中的某个文本。我的代码在这里
library(ggplot2)
labels <- c("green", "blue", "orange", "blue", "green","red","purple","black")
num_1 <- c(1,2,3,4,5,6,7,8)
num_2 <- c(5,9,3,7,4,3,1,8)
df <- data.frame(labels,num_1,num_2)
p <- ggplot(df, aes(num_1,num_2,label=labels)) + geom_text()
p
Run Code Online (Sandbox Code Playgroud)
例如,我想通过将其字体更改为粗体或将其颜色更改为黄色来突出显示文本“绿色”。两者都有效,但我无法让它发挥作用。我尝试过使用 gghighlight 但还没有找到让它工作的方法。
我需要一个 python 正则表达式来查找具有五个连续辅音的单词。
这些话会起作用——
tnortvcvni (rtvcvn)
kahjdflka (hjdflk)
Run Code Online (Sandbox Code Playgroud)
但这些词不会(没有五个连续的字母没有元音) -
peanut
butter
jelly
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用按钮来过滤 JSON 中的数据。每当单击按钮时,它都会使用过滤后的 JSON 数据更新状态。然后它将返回包含更新数据的列表。现在我有四个按钮来过滤四种不同的“类型”,但代码根本不起作用。
import React, { useState, useEffect } from 'react';
import * as moment from 'moment';
import PollCard from './PollCard'
function PollList() {
const [polls, setPolls] = useState(null);
const [loading, setLoading] = useState(false);
const range = 30
var dateRange = moment().subtract(range, 'days').calendar();
async function fetchMyAPI() {
let response = await fetch(url)
const json = await response.json()
var data = json.filter(e => Date.parse(e.endDate) >= Date.parse(dateRange))
setPolls(data.reverse())
setLoading(true);
}
useEffect(() => {
fetchMyAPI();
}, [])
if (!loading) {
return …Run Code Online (Sandbox Code Playgroud) python ×5
pandas ×4
ggplot2 ×2
ios ×2
javascript ×2
reactjs ×2
swift ×2
bokeh ×1
csv ×1
dataframe ×1
matplotlib ×1
r ×1
react-hooks ×1
regex ×1
scatter-plot ×1
uisearchbar ×1
uitableview ×1