python-3.x

Pandas: get the min value between 2 dataframe columns

会有一股神秘感。 提交于 2021-02-18 21:11:38
问题 I have 2 columns and I want a 3rd column to be the minimum value between them. My data looks like this: A B 0 2 1 1 2 1 2 2 4 3 2 4 4 3 5 5 3 5 6 3 6 7 3 6 And I want to get a column C in the following way: A B C 0 2 1 1 1 2 1 1 2 2 4 2 3 2 4 2 4 3 5 3 5 3 5 3 6 3 6 3 7 3 6 3 Some helping code: df = pd.DataFrame({'A': [2, 2, 2, 2, 3, 3, 3, 3], 'B': [1, 1, 4, 4, 5, 5, 6, 6]}) Thanks! 回答1: Use df.min(axis=1) df['c'] = df.min(axis=1) df Out[41]: A B c 0 2 1 1 1 2 1 1 2 2 4 2 3 2 4 2 4 3 5 3 5 3

Cannot import name 'spawn' for pexpect while using pxssh

廉价感情. 提交于 2021-02-18 21:10:01
问题 This is the code I am trying to run: from pexpect import pxssh s = pxssh.pxssh() if not s.login ('myip', 'myusername', 'mypassword'): print ("SSH session failed on login.") print (str(s)) else: print ("SSH session login successful") s.sendline ('ls -l') s.prompt() # match the prompt print (s.before) # print everything before the prompt. s.logout() The error which I am getting on running this is : Traceback (most recent call last): File "test_pexpect.py", line 1, in <module> from pexpect

Connection refused with postgresql using psycopg2

老子叫甜甜 提交于 2021-02-18 20:42:19
问题 psycopg2.OperationalError: could not connect to server: Connection refused Is the server running on host "45.32.1XX.2XX" and accepting TCP/IP connections on port 5432? Here,I've open my sockets. tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 11516/postgres tcp6 0 0 ::1:5432 :::* LISTEN 11516/postgres I googled that I should modify this pg_hba.conf ,but in my postgresql root files, I didn't find this file at all. Also I've succeed in connecting my another server. Thanks. Here,I've modified the pg_hba

How do I set the asyncio event loop for a thread in Python?

為{幸葍}努か 提交于 2021-02-18 20:41:06
问题 I'm trying to create two threads that each have their own asyncio event loop. I've tried the following code but it doesn't seem to work: import asyncio from threading import Thread def hello(thread_name): print('hello from thread {}!'.format(thread_name)) event_loop_a = asyncio.new_event_loop() event_loop_b = asyncio.new_event_loop() def callback_a(): asyncio.set_event_loop(event_loop_a) asyncio.get_event_loop().call_soon_threadsafe(lambda: hello('a')) def callback_b(): asyncio.set_event_loop

Object has no attribute '.__dict__' in python3

雨燕双飞 提交于 2021-02-18 20:11:57
问题 I have a test that passes in Python2 and fails in Python3, I'm trying to find out why. The test fails at the following line: self._timeseries[0].resource.__dict__ With the error: AttributeError: 'Resource' object has no attribute '__dict__' If I debug the test, and print the object in the debugger, I can see the following: (Pdb) p self._timeseries[0].resource.__dict__ OrderedDict([('type', 'type_value'), ('labels', {'label1': 'value1', 'label2': 'value2', 'label3': 'value3'})]) If I do the

Python configparser will not accept keys without values

穿精又带淫゛_ 提交于 2021-02-18 19:55:10
问题 So I'm writing a script that reads from a config file, and I want to use it exactly how configparser is designed to be used as outlined here: http://docs.python.org/release/3.2.1/library/configparser.html I am using Python 3.2.1. The script, when complete, will run on a Windows 2008 R2 machine using the same version of Python, or assuming compatibility, the latest version at the time. #!/user/bin/env python import configparser config = configparser.ConfigParser() config.read('c:\exclude.ini')

How can I validate a post request from an raw HTML form (No django form used)

ぃ、小莉子 提交于 2021-02-18 19:43:55
问题 def update(request, property_id): obj = get_object_or_404(PropertyModel, property_id= form = PropertyModelForm(request.POST or None, instance= if form.is_valid(): form.save() template = 'form.html' context = { 'form': form } return render(request, template, context) have done using Django model from but want to do it using HTML form 回答1: I'd recommend you to use Django forms but if that's not an option you can go ahead and use Javascript and manually checking on the views, here's an extremely

How can I validate a post request from an raw HTML form (No django form used)

雨燕双飞 提交于 2021-02-18 19:43:14
问题 def update(request, property_id): obj = get_object_or_404(PropertyModel, property_id= form = PropertyModelForm(request.POST or None, instance= if form.is_valid(): form.save() template = 'form.html' context = { 'form': form } return render(request, template, context) have done using Django model from but want to do it using HTML form 回答1: I'd recommend you to use Django forms but if that's not an option you can go ahead and use Javascript and manually checking on the views, here's an extremely

How can I validate a post request from an raw HTML form (No django form used)

喜你入骨 提交于 2021-02-18 19:42:10
问题 def update(request, property_id): obj = get_object_or_404(PropertyModel, property_id= form = PropertyModelForm(request.POST or None, instance= if form.is_valid(): form.save() template = 'form.html' context = { 'form': form } return render(request, template, context) have done using Django model from but want to do it using HTML form 回答1: I'd recommend you to use Django forms but if that's not an option you can go ahead and use Javascript and manually checking on the views, here's an extremely

Swapping first and last name positions

淺唱寂寞╮ 提交于 2021-02-18 19:12:48
问题 I need some help in writing the body for this function that swaps the positions of the last name and first name. Essentially, I have to write a body to swap the first name from a string to the last name's positions. The initial order is first name followed by last name (separated by a comma). Example: 'Albus Percival Wulfric Brian, Dumbledore' The result I want is: 'Dumbledore, Albus Percival Wulfric Brian' But I've tried the following and I'm still not getting the right answer: temp = name