我的工作:
在这一点上,我想我可以通过使用层次结构和轮廓找到它:下面是我的工作
for i in range (len( contours_region)): #I already have X,Y,W,H of the checkbox through
#print(i) #cv2.connectedComponentsWithStats
x = contours_region[i][0][1] #when detecting checkbox
x_1 = contours_region[i][2][1]
y = contours_region[i][0][0]
y_1 = contours_region[i][2][0]
image_copy= image.copy()
X,Y,W,H = contours_info[i]
cv2.drawContours(image_copy, [numpy.array([[[X,Y]],[[X+W,Y]],[[X+W,Y+H]],[[X,Y+H]]])], 0, (0,0,255),2)
gray = cv2.cvtColor(image_copy, cv2.COLOR_BGR2GRAY)
ret,bw = cv2.threshold(gray,220,255,cv2.THRESH_BINARY_INV)
contours,hierarchy = cv2.findContours(bw[x:x_1, y:y_1], cv2.RETR_CCOMP,1)
print('-----Hierarchy-----')
print(hierarchy)
print('-----Number of Contours : '+ str(len(contours)))
cv2.imshow('a', image_copy)
cv2.waitKey(0)
Run Code Online (Sandbox Code Playgroud)
我得到了这个结果(一些高轮廓,一些高层次)
Run Code Online (Sandbox Code Playgroud)-----Hierarchy----- [[[-1 -1 1 -1] [ 2 -1 -1 0] …
习惯 plt.hist。但是,我认为 histtype='bar' / 'stepfilled' / 'barstacked' 之间没有区别。这是我的试用代码
import numpy as np
import matplotlib.pylab as plt
x1 = np.random.normal(0, 0.8, 1000)
x2 = np.random.normal(-2, 1, 1000)
x3 = np.random.normal(3, 2, 1000)
fig ,ax=plt.subplots(3)
kwargs = dict(alpha=0.3, normed=True, bins=40)
ax[0].hist(x1, **kwargs)
ax[0].hist(x2, **kwargs)
ax[0].hist(x3, **kwargs)
kwargs1 = dict(histtype='stepfilled', alpha=0.3, normed=True, bins=40)
ax[1].hist(x1, **kwargs1)
ax[1].hist(x2, **kwargs1)
ax[1].hist(x3, **kwargs1)
kwargs2 = dict(histtype='barstacked', alpha=0.3, normed=True, bins=40)
ax[2].hist(x1, **kwargs2)
ax[2].hist(x2, **kwargs2)
ax[2].hist(x3, **kwargs2)
plt.show()
Run Code Online (Sandbox Code Playgroud)
我正在制作 2 y 轴图表。我希望 Y 轴标签具有与刻度颜色相同的颜色。但我还是做不到
<ComposedChart height={300} data={chart_data}>
<CartesianGrid ... />
<XAxis ..... />
<YAxis .....
label={{ .... fill:'#FDF652' }} /> #Fill here not working
<YAxis ....
label={{ .... fill:'#535184'}} /> #Fill here not working
<Tooltip ......... />
<Area fill="#8884d8"/> #Fill here working
<Bar fill="#535184" ..../> #Fill here working
<Legend ............ />
</ComposedChart>
Run Code Online (Sandbox Code Playgroud)
当我添加时fill
,Area
它Bar
可以工作并且有颜色。但是当我添加时fill
它<YAxis label>
不起作用
我想再添加 1 个列,其中细分客户是否至少销售了一种产品。数据示例:
ProductID Customer Status
1 John Not sold
2 John Not Sold
3 John Sold
Run Code Online (Sandbox Code Playgroud)
我的预期结果
ProductID Customer Status Sold_at_least_1
1 John Not sold Yes
2 John Not Sold Yes
3 John Sold Yes
4 Andrew Not Sold No
5 Andrew Not Sold No
6 Brandon Sold Yes
Run Code Online (Sandbox Code Playgroud)
这是一个示例数据。由于无法提取数据给您带来的不便,敬请谅解。顺便说一句,感谢任何帮助。
数据样本:
a=pd.DataFrame({'Col1':[1,2,'a','b',1.5],'Col2':['a','b','c',2,3],'Col3':['a',1.2,1.3,1.4,2]}))
Col1 Col2 Col3
0 1 a a
1 2 b 1.2
2 a c 1.3
3 b 2 1.4
4 1.5 3 2
Run Code Online (Sandbox Code Playgroud)
正如您在列中看到的那样,有str
, int
, float
。
我下面的代码是检查类型并计算它的数量。虽然有点业余,还是请看一下。
def checkDtype(df='DateFrame',s='Series'):
ListOfType={}
for i in df.columns: #Walk through every columns of DataFrame
ListOfType[i]=dict(Float=0,Int=0,Str=0)
for a in df[i]: #Walk through every row of the selected column
if type(a) is float:
ListOfType[i]['Float']+=1
if type(a) is int:
ListOfType[i]['Int']+=1
if type(a) is str:
ListOfType[i]['Str']+=1
return ListOfType
Run Code Online (Sandbox Code Playgroud)
`
b= checkDtype(df=a) #The …
Run Code Online (Sandbox Code Playgroud) 这是来自源代码的示例代码:https://docs.python.org/3/howto/logging.html
import logging\nlogging.basicConfig(filename='example.log', encoding='utf-8', level=logging.DEBUG)\nlogging.debug('This message should go to the log file')\nlogging.info('So should this')\nlogging.warning('And this, too')\nlogging.error('And non-ASCII stuff, too, like \xc3\x98resund and Malm\xc3\xb6')\n
Run Code Online (Sandbox Code Playgroud)\n我认为level=logging.DEBUG
下面的代码
logging.basicConfig(filename='example.log', encoding='utf-8', level=logging.DEBUG)\n
Run Code Online (Sandbox Code Playgroud)\nlogging
只接受logging.DEBUG
。那为什么info
,,warning
工作error
我有两个不同的列表:
key = ['key1', 'key2', 'key3']
value = ['value1', 'value2', 'value3']
Run Code Online (Sandbox Code Playgroud)
我想像这样映射它:
dictionary = {'key1':'value1',
'key2':'value2',
'key3':'value3'}
Run Code Online (Sandbox Code Playgroud)
我试过这个:
dictionary = {key, value}
Run Code Online (Sandbox Code Playgroud)
但我得到了这个结果:
TypeError: dict expected at most 1 arguments, got 2
Run Code Online (Sandbox Code Playgroud) python ×4
cv2 ×1
dataframe ×1
dictionary ×1
logging ×1
matplotlib ×1
numpy ×1
opencv ×1
pandas ×1
postgresql ×1
python-3.x ×1
reactjs ×1
recharts ×1