I am trying to count number of rows that has values in at least 3 columns so the output based on the image shared should be 4. I tried using the code below but it is resulting in the same shape as the whole table which is 7.
counts = df[(df[['a', 'b', 'c', 'd]] != 'no_label').count(axis=1) >= 3]
i have a value that is generated as the max value for example from this list [0.6000001, 0.3, 0.3, 0.4]
clearly the maximum value is 0.6000001 but python does not seem to be able to recognize this value as the maximum. i have tried so many ways to solve it but to no avail. even when changing...
the code below intends to take the maximum value that is calculated for each of the variable but after the max value is obtained I am not sure how to ensure there are no 2 or more values are the same in the if else loop as if 'a' has the max value of 3 and 'b' also has the max value of 3 then...
I am iterating over 2 variables below and after the calculation are done, i'd like to append the dataframe to add the rows after each iteration, but what is happening now is that the row is getting replaced instead of getting added.
pre = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
post = [0, 1, 2, 3, 4...
I have a dataframe as shown in the picture and what I am trying to do is to calculate the number of occurrences based on the values in 2 columns and then calculate the percentage of the occurrences. I have tried the following code but it gives me a zero value in the end and i don't know why...
I would like to generate a multi index dataframe that looks like the image attached. how do i do this in python?
I tried this approach but it doesn't give me the output as expected:
https://stackoverflow.com/questions/28289440/creating-an-empty-multiindex
i have a column in a dataframe that contains values in the form or tuples (example: ('A',) ) and I want to convert these values to string format so that ('A',) becomes 'A'
How do I do this in python for a dataframe? Thanks.
I have computed a line from point A to point B by just subtracting the coordinates as below:
line = np.array (x2-x1, y2-y1)
I am not sure if I need to form the formula for this line first by computing the slope and intercept but I continued my code as below, slope being m and b being the...
I have code snippet as below and when i run it, the dataframe seems to append after every loop and does not add the previous row into the frame, so at each time only one row is populated into the new dataframe. How do I ensure that the append function adds the previous row as well...
Hi, I felt like I have to learn more than one coding language, and wanted to strengthen my coding skills in general. I am good with Relap5 but I want to learn OpenFoam. is what I did logical and going to be worth the pain ? also I only have the Relap5 version of a windows ,is it possible to run...
Hi!
I would like solve this kind of relation:
\phi = \int_0^r \phi (r') 4 \pi r'dr'
But I don't know how to proceed...
Can you advise me ?
Thank's in advance !
I want to find the numerical solution to the following nested integral in Python
\frac{K!}{(K-M)!}\int_{x_1=0}^{y}\int_{x_{2}=x_1}^{\max(x_1,\,y-x_1)}\cdots
\int_{x_M=x_{M-1}}^{\max(x_{M-1},\,y-\sum_{m=1}^{M-1}x_m)}
\frac{1}{(1+x_M)^{K-M+2}}\prod_{m=1}^{M-1}...
Hi,
Mostly i work with Octave / Matlab but i am trying to get into python also.
Lately i have a couple problems where my numbers can't be represented in binary64 or float64 default format because they exceed the max of 1.8x10^308. Is there a common way people deal with this (without toolkits)...
Hi all;
I've already posted to P_Anywhere's site but... I'm trying to run a script that needs a data file piped to it. Now P_ Anywhere gives you a resident directory and mine contains the program and the data file. Sooo...
bonds.py ethane.xyz maybe? Nah. Doesn't like that. But! I did get it to...
I would like to ask about unitary transformation.
UA(IV)
UB*UA(IV)
UAT(UB*UA(IV))=UB(IV)
UB(IV)*(X)
IVT(UB(IV)*(X))=UB(X)
UBT*UB(X)=X
From the information above, UAT,IVT and UBT are the transpose of the complex conjugate. The aim of this code is to get the value of X in the step 4. This is...
I defined a simple prime function and then I append each number to an array up to 1 million and then later 2 million. In both cases, Python IDLE gives me the answer in 4 and 9 seconds respectively, but Spyder and Jupyter Notebook gave me in 12 and 24 seconds. I wonder why this happened. The time...
Hello,
I have made a python script that splits my desired star.data file from a MESA model into two distinct files that I need to use in SNEC link here:
https://github.com/abostroem/SNEC
My script is here :
https://github.com/ilaur/SNEC-Split
When I try to run SNEC with my custom profile it...
Hi
I want to learn and understand web development, and just knowing what to do is not enough for me; I, to the extent it is possible, want to know how the web works. So, if I develop a web app or website with Flask, I want to know what is going on under the hood (it's just how my head works...
Hey all, I think most of you know me and probably this question will sound silly but anyways, I am learning python over a 3 month now and The course in the school is over and there will no other course. I want to learn more and is there any source you can recommend me.
What I know:
1-I know...
Hello members of PF, my name is Reid Honeycutt. I am a mathematics major at American River College, Sacramento. My mathematical interests are primarily in the areas of algebra and logic. I also love physics and materials science, economics, and programming in python.
My motivation in joining...
Hi there.
I have a question about the damped pendulum. I am working on an exercise where I have already numerically approximated the solution for a simple pendulum without dampening. Now, the excercise says that I can simply change the code of this simple situation to describe a pendulum with...
Homework Statement
I'm taking an online course in Stat. Mech. and we're working on Markov chain Monte Carlo methods. One of the programs supplied uses the following:
Mentor note: Added code tags
import numpy
neighbor = [[1, 3, 0, 0], [2, 4, 0, 1], [2, 5, 1, 2],
[4, 6, 3, 0], [5...
Hi
I wish to use Python to create art which can be exported as dxf files for use with laser cutters.While Processing is available for Python, it only creates raster images. What are my options if I want to create vector images?
This may be the wrong forum for this question... If it is, where...
Hi all,
I performed a resonance experiment over the past two weeks, in which I collected the intensity of a Fabry-Perot cavity whilst adjusting the mirror distance with a piezo-element (the specific setup of the experiment is fairly detached from the question I will ask). My raw data is...
Hello,
I've learned some of the basics of python through the sololearn Python 3 course (I also started the first week of the MIT Intro to computer science and programming on edx.org, but I found it beyond beginner level and decided to go through the sololearn Python 3 first).
My company...
hello all i am a new member on Physics Forum
i am a last year master student in fundamental physics ( again )
and also have done a master in condense mater and nano-science
i worked on noble solid /amorphous interface in my first master internship ( DFT and ab initio molecular dynamic using...
Code: https://pastebin.com/5LajNBpj
So I was messing with VPython, trying to create an Earth-Moon System. I got the actual gravity to work, and can create some nice ellipical orbits. However I run into trouble trying to make the actual (almost) circular orbit of the moon.
I know that the...
Hello everyone, I am trying to create a sign out sheet as if I am a teacher and its so then people can sign out electronically. I know very little python and I have googled most things. I have never worked with a text file before. I am trying to make so it will ask my name, destination, and time...
I have a python script for which the input data are coming from Matlab. I have tried to use pymatlab, but it is failing. Can anyone suggest any other method?
Hi everybody.
In Python there is a library called chaospy. One useful command is cp.orth_ttr which generates a polynomial expansion, e. g. a series of orthogonal polynomials or orders zero, one, two... for a random variable e.g normal, uniform...
For more information see...
I came across this article about using Pandas in Python to read in a multi-tab spreadsheet to Python, and work with the data then write back to an Excel spreadsheet...
Hello everyone. I have a Python code which calculates, given a continuos uniform random variable U(-1,1), the order of a interpolation polynomial and a set of points the evolution of a function of this random variable. i.e.
v0 = cp.Uniform(-1,1)
t = np.linspace(0, 10, 10)
order=1
.
.
.
plt.plot...
Homework Statement
This is related to Astronomy & python . I am trying free-up sources on TS map on a galactic source with python script. But when I run the script, at the end of the process, I get the following run time error.
Traceback (most recent call last):
File "find_new_sources.py"...
I'm working on an assignment where I'm required to numerically find the energy of a delta-potential's bound state. To do this, we've converted the time-independent schrödinger equation to an eigenvalue problem with E the eigen value, ψ the eigen vector and H a matrix as follows:
with ##t =...
If someone has used the python program POPPY, I'd like some help. How can I set up two wavefronts entering at slightly different angles, and then see the interference pattern?
I have a simulation that involves a lot of dense linear algebra with a lot of complex arrays, that was written in python's numpy and then sped up with cython. Unfortunately I'm stuck with python's GIL (global interpreter lock), which prevents the use of numpy with multi-threaded code.
I'm...
Hello, I am assigned to write a code using bisection method (aka binary search method)
The equation is 10sin(x) - x^3 - N where N = 1,2,3,4,5,6,7
My code is
from math import sin
def neg(a, b):
return a*b> 0
def bisectx(funcx, lowx, highx,n):
assert not neg(funcx(lowx,n), funcx(highx,n))...
I'm working on a convolutional neural network project that classifies histopathological images of breast tumors. All my code is in python. Part of the image preprocessing involves appearance normalisation to account for the variation in histological staining. The only code for the preprocessing...
Hello,
I was reading an example on binning data, where a continuous variable is transformed into a categorical variable. The dataframe name is df, and the continuous variable's column's name is 'horsepower'. We would like to transform the continuous variable feature into a categorical feature...
Hello,
I am new to both Python and machine learning. I am trying to learn by reading books on machine learning using Python. I started with this book. I could manage the first 3 chapters (although I had to dissect the codes on Github because not all the codes are included and explained in the...
Hi guys. Just wanted to see if I could get a point on this problem I'm having.
I'm using a book to learn Python3 and I'm using SublimeText as an editor.
The book initially told me to configure Sublime for Python3 by typing this into a blank Sublime file:
{
"cmd": ["/usr/local/bin/python3"...
Homework Statement
I'm plotting moving particles and I need a way to refresh the graph space with every loop. Meaning I want the points to NOT leave a trail of other points behind them . Basically I want to get rid of the old points as I plot new ones.
Homework Equations
N\A
The Attempt at a...
I'm new to this forum, as well as Python, so bare with me, won't you:)
Ok, so I have this GUI written in python and utilizing PYQT5. I have a functioning version, but I now want to add a QpushButton that executes a method called add_Bladebox. This method adds a doublespinbox to the gui. The...
I'm creating a Monte Carlo simulation of the 2D Ising Model for a graduate course in computational materials science. Part of the assignment is to calculate the uncertainty in the calculation of the average magnetization per spin. To do so, we are told to find the correlation time for our data...
Hello,
Thank you for taking time to read my post.
I have a discrete set of data points that represent an acceleration signal. I want to take the integral of this set of points twice so as to get a function which represents the position over time.
To accomplish this, I have taken the FFT of the...
Homework Statement
I need to calculate the derivative of a function using discrete Fourier transform (DFT). Below is a simplified version of my code (just for sin function) in python
Homework Equations
from __future__ import division
import numpy as np
from pylab import *
pi = np.pi
def...
Homework Statement
So currently I'm working with user-defined functions. Initially, the code inside the user-defined function worked but when I attempted to change it into a user-defined function, it produces incorrect values.
Homework Equations
No need for any equations
The Attempt at a...
Hi
I have to run a few algorithms using Python on PNG-images. However, I also know that PNG is compressed... How do I do this? I need to learn the following:
1: Extracting the RGB information about the pixels.
2: Isolating parts of the image (for example, importing an image and only working on...
Hi
Lets say I have a txt file with m rows with n columns of numbers of the form:
Lets say I want to take every p'th row and take the second and third columns and turn it into a \frac{m}{p}\times 2 matrix. How would I go about doing that?