I have a dataframe that looks like this one: I am implementing K-Neighbors Algorithm with Pandas and Numpy and when getting a list of dataframes, I can’t remove the one I am looping on with a list. How to remove the one I am looping on from the list so I can concatenate the remaining ones on cross fold validation?
Tag: numpy
How to combine two entry values in a column
In the dataset, the column “Erf Size” has entries like 1 733 and 1 539 etc. Note that the Dtype of this “Erf Size” column is object. I would like to join these 1 733 and 1 539 into 1733 and 1539 etc. original dataset expected output Answer I think you can fix this with pd.to_numeric. This will change the
PyQt5/Pyqtgraph Get Numpy Array for What is Currently on the Scene
I have a pg.GraphicsLayoutWidget with some images and some ROIs displayed . I would like to get obtain a numpy array for what is currently on the scene, just like the export command in the context menu of the viewbox . Let an arbitrary RGB image (i.e. a numpy array) image be given. For example , I am using https://drive.google.com/drive/folders/1ejY0CjfEwS6SGS2qe_uRX2JvlruMKvPX?usp=sharing
Python: need efficient way to set column value based on another column value
New Python user here, so I appreciate any ideas for best practices in addition to the issue I’m seeking advice on. I have code that works for a small number of records, but when I run it on a large dataframe, it takes too long. I’ve done a lot of reading on this issue, and there are several similar posts
simple Neural Network gives random prediction result
I have been trying to build a simple neural network myself (3 layers) to predict the MNIST dataset. I referenced some codes online and wrote some parts my own, the code runs without any errors, but something is wrong with the learning process. It seems like the prediction result is all “random”. Applying the learning process to the network and
Pandas DataFrame: How do I create numerical values out of numerical values from another column?
I have probably not explained my issue right in the headline, so let’s try to clarify it here. I want to categorise values from 1 column into a new one. The first ten lines in my data set are this: And the code I use is this I think this can be done easier with a user-defined function, but I
Updating column value based on nan value of other column
I have this simple function with 2 columns. What I’m trying to do is to check what group has a number of nan and change it to a new desired value. Here’s a code snippet: Before: This is how the data looks like, you can assume numbers are sorted. In my example I know where nan and since it was
How can I write a Python function that loops through a list of dataframes and drops duplicate rows?
I have a “Main” dataframe which is being continuously built. Each month I merge new data into that one, however I want to remove rows that exist in both dataframes. Example “Main” Name Date Begin Time End Time Bob 03/10/2022 11:04 14:10 Dirk 05/12/2022 13:15 16:56 Steve 01/13/2022 11:11 13:13 “Other” Name Date Begin Time End Time Rog 03/14/2022 11:44
Filtering out rows based on other rows using pandas
I have a dataframe that looks like this: I can’t seem to figure out a way to filter out certain rows based on the following condition: If there are two entries under the same companyId, as is the case for 198236 and 153421, I want to keep only the entry where type is actual. If there is only one entry
How to scatter plot two concentric circles with Numpy and Matplotlib
I’m trying to recreate the following plot with Numpy and Matplotlib as part of a question, but I’m struggling to get the “random aspect” of the plot: I’ve already managed to create the two circles and plot them with this code: But I don’t know how to make them get this random scattering, like in the example image. I know