I have 4 groups (research, sales, manu, hr) and each group has 2 categories (0 & 1). I am trying to plot the average scores for each group in the features in the list ratings. The code that gives me the means looks like this (with depts = [‘research’, ‘sales’, ‘manu’, &…
Tag: pandas
Convert result of sum of timedeltas in Python
I have the output below from a sum of a timedelta list in a column on my dataframe. How do I get values converted to hours minutes and total seconds? Answer afaik, there’s no built-in functionality for this. But you can create your own. For example for formatting to a string in H:M:S format or splitting…
Is there a more efficient way to find and downgrade int64 columns with to_numeric() in Python Pandas?
tl;dr: Need help cleaning up my downcast_int(df) function below. Hello, I’m trying to write my own downcasting functions to save memory usage. I am curious about alternatives to my (frankly, quite messy, but functioning) code, to make it more readable – and, perhaps, faster. The downcasting functi…
How to plot simple moving averages with stock data
I am trying to plot simple moving averages (SMA) using Apple’s stock price. I have lines below: But the plotting isn’t successful. What did I do wrong, and how I can correct it? Answer From the code you posted, it seems as though you didn’t set the index of the dataframe after loading the da…
How to correctly read specific csv column
Hey everyone my question is kinda silly but i am new to python) I am writing a python script for c# aplication and i got kinda strange issue when i work with csv document. When i open it it and work with Date column it works fine But when i try to work with another columns it throws error KeyError:
Python: Convert a pandas Series into an array and keep the index
I’m running a k-means algorithm (k=5) to cluster my Data. To check the stability of my algorithm, I first run the algorithm once on my whole dataset and afterwards I run the algorithm multiple times on 2/3 of my dataset (using a different random states for the splits). I use the results to predict the c…
How to perform index/match excel function equivalent using pandas?
I am facing the below challenge. For instance, let the dummy dataframes be, Let another dataframe be, The output dataframe should be the following, My train of thought was to create dictionary(s), in this case, would be, followed by this function, I am always getting the following error, Also I think this is …
Extrapolating using Pandas and Curve_fit error func() takes 3 positional arguments but 4 were given
I’m using the code from another post to extrapolate values. I changed the func() so that it is linear not cubic however I get an error “func() takes 3 positional arguments but 4 were give” Extrapolate values in Pandas DataFrame is where I got the original code. My question is how would I cha…
How can I remove two or more objects of a list from a single input in Python?
This is my sample database: In my script now, I am adding elements to the list with the following code: So now if type “2 JO” my list will have two new elements “John” and “John”. Now I want to do exactly the same but for eliminating objects of a list. I tried to replace th…
How to create sum of columns in Pandas based on a conditional of multiple columns?
I am trying to sum two columns of the DataFrame to create a third column where the value in the third column is equal to the sum of the positive elements of the other columns. I have tried the below and just receive a column of NaN values DataFrame: Answer You can use df.mask here and fill value less than