python-3.x

Apply function per group of values of a key in list of dicts

為{幸葍}努か 提交于 2021-02-11 13:52:42
问题 Let's suppose I have this: my_list = [{'id':'1','value':'1'}, {'id':'1','value':'8'}, {'id':'2','value':'2'}, {'id':'2','value':'3'}, {'id':'2','value':'5'}, ] and I want to apply a function (eg shuffle ) for each group of values separately for the key id . So I would like to have this for example: my_list = [{'id':'1','value':'1'}, {'id':'1','value':'8'}, {'id':'2','value':'3'}, {'id':'2','value':'5'}, {'id':'2','value':'2'}, ] Therefore I do not want something to change between the

tensorflow backend error. AttributeError: module 'tensorflow' has no attribute 'name_scope'

。_饼干妹妹 提交于 2021-02-11 13:51:19
问题 I'm using Version: 2.1.0 of TensorFlow and 2.3.1 of keras. While importing any module of keras i'm facing below tensorflow back-end error. import pandas as pd, numpy as np, os, re, json, math, time from keras.models import Sequential from keras.layers import Dense from keras.wrappers.scikit_learn import KerasRegressor from sklearn.model_selection import cross_val_score from sklearn.model_selection import KFold from sklearn.preprocessing import StandardScaler from sklearn.pipeline import

text file into a nested python dictionary more than one variable

我们两清 提交于 2021-02-11 13:50:16
问题 I have a text file that is formatted as follows: [one] A = color B = Petals C = Junk [two] Z = 10 A = freq corner = yes [three] D = code status = 45 I'm trying to read this file into a nested dictionary so that it looks like this: {'one':{'A':'color','B':'Petals','C':'Junk'}, {'two':{'Z':'10','A':'freq':'corner':'yes'}, {'three':{'D':'code','status':'45'}} I tried import re ini_sections = [] ini_dict = {} x = 0 with open(path,'r') as f: for line in f: re_found = re.findall('\[(.*?)\]',line)

Label keeps running off edge of ScrollView screen x axis Kivy

我怕爱的太早我们不能终老 提交于 2021-02-11 13:50:10
问题 I'm creating a chat screen, adding a Label to my GridLayout everytime the send button is pressed. However, my Labels run off the side of the screen when the text becomes too long, I would like them to wrap round and the text to go onto a new line but this isn't happening and I'm not sure why. <ChatPage>: name: "chat_page" layout_content: layout_content NavigationLayout: id: nav_layout MDNavigationDrawer: NavigationDrawerIconButton: text: "Test" on_release: app.root.current = "login"

Matplotlib Quiver plot matching key label color with arrow color

此生再无相见时 提交于 2021-02-11 13:47:47
问题 Using matplotlib, python3.6. I am trying to create some quiverkeys for a quiver plot but having a hard time getting the label colors to match certain arrows. Below is a simplified version of the code to show the issue. When I use the same color (0.3, 0.1, 0.2, 1.0 ) for a vector at (1,1) and as 'labelcolor' of a quiverkey I see 2 different colors. q=plt.quiver([1, 2,], [1, 1], [[49],[49]], [0], [[(0.6, 0.8, 0.5, 1.0 )], [(0.3, 0.1, 0.2, 1.0 )]], angles=[[45],[90]]) plt.quiverkey(q, .5, .5, 7,

Error involving Tkinter/matplotlib “no display name and no $DISPLAY environment variable” on CentOS

ぃ、小莉子 提交于 2021-02-11 13:46:37
问题 Most relevant questions I've seen here are not fixing my issue. I'm writing a program that uses matplotlib and tkinter to make a GUI. I'm running CentOS7. I get this when trying to run python36 testGraph.py on my server: Traceback (most recent call last): File "testGraph.py", line 167, in <module> app = SeaofBTCapp() File "testGraph.py", line 57, in __init__ tk.Tk.__init__(self, *args, **kwargs) File "/usr/lib64/python3.6/tkinter/__init__.py", line 2020, in __init__ self.tk = _tkinter.create

How to fake type() response on Python class

你说的曾经没有我的故事 提交于 2021-02-11 13:46:32
问题 While it has been previously answered how to fake isinstance, in this case I'm trying to fake the response given by type() while reviewing the TypeChanger class. For context Im just trying to understand if is doable or not and why for Python 3.X This is my current test setup: def test(): class TypeChanger(): @classmethod def __instancecheck__(cls, instance): if instance is list: return True else: return False @property def __class__(self): return list def extra_functionality(self): return

How do you convert a column containing year & quarter in a str format as '1947q1' to date format column where both year and quarter are considered?

帅比萌擦擦* 提交于 2021-02-11 13:44:38
问题 **Year_qtr GDP ADJ_GDP** 2 1947q1 243.1 1934.5 3 1947q2 246.3 1932.3 4 1948q3 250.1 1930.3 5 1949q4 260.3 1960.7 Tried parse() from dateutil package but didnt wwork. Result dataframe should have 'Year_qtr' column as date values instead of object. 回答1: pandas already can do this out of the box! you can cast to datetime right away: import pandas as pd df = pd.DataFrame({'Year_qtr': ['1947q1', '1947q2', '1948q3', '1949q4']}) df['datetime'] = pd.to_datetime(df['Year_qtr']) # df # Year_qtr

TypeError: string argument expected, got 'bytes'

余生颓废 提交于 2021-02-11 13:42:10
问题 I would like to convert the below hex sequences to images, in the process of sifting through quite a number of problems that are similar to mine none have come close as to that solved in https://stackoverflow.com/a/33989302/13648455, my code is below, where could I be going wrong? data = "2a2b2c2a2b2c2a2b2c2a2b2cb1" buf = io.StringIO() for line in data.splitlines(): line = line.strip().replace(" ", "") if not line: continue bytez = binascii.unhexlify(line) buf.write(bytez) with open("image

Configure STP protocol via scapy

夙愿已清 提交于 2021-02-11 13:42:00
问题 I need to generate and STP traffic using scapy and when I visualize it via wireshark I get an output similar to the caption shown below: when I run this code: from scapy.all import STP import scapy from scapy.all import * data='STP' sendp(Ether(dst="01:80:c2:00:00:00")/LLC(dsap=0xaa, ssap=0xaa)/STP(bpdutype=0x00, bpduflags=0x01, portid=0x8002)/data, iface="eth1", count=200) this is my wireshark output I don't know how to change the organization code to 00:00:0c, because I believe it's the one