I’m using Python 3.8.5. My OS is Kubuntu 18.04. I installed Spyder and Poetry via pipx: Within my project folder, I installed pandas and spyder-kernels as dependencies: I can open Spyder just fine: In Spyder -> Preferences -> Python interpreter, I added the path to the Python interpreter for the p…
Tag: pandas
How to use apply() to change data in a pandas data frame to lowercase?
I have this pandas dataframe: And what I want to do is use apply() with a function to convert all the data to lowercase. I couldn’t find anything on the internet showing how to do this, I am currently stuck with this. however it gives me error that series object has no attribute lower. Any help greatly …
How to check if a substring in a pandas dataframe column exists in a substring of another column in the same dataframe?
I have a dataframe with columns like this: I want to create a list with values from A that matches values from B. The list should look like [- 5923FoxRd, Saratoga Street, Suite 200…]. What is the easiest way to do this? Answer To make a little go a long way, do the following: Create a new series for eac…
How to plot data from multiple dataframes with seaborn relplot
I want to plot two lines on the same set of axes. It seems sns.relplot is creating a facetted figure, and I don’t know how to specify that I want the second line on the same facet as the first. Here’s a MWE How do I get the red and blue lines on the same plot? I’ve not had luck
Pandas sort column values with “0” values at end of column
I have a dataframe which looks like this I would like to have “0” values at the end when sorting so my resulting dataframe looks like this. Is there a simple (1 line of code) solution? Answer First mask the zeros then use argsort on column A to get the indices that would sort the dataframe:
Pandas: str.contains first word followed by colon
I am trying to understand how to identify columns which start with a word, which is immediately followed by a colon. I tried identifying that it should match less then 9 characters, followed by a colon – but with no lack. The example is below: Michael: this should be picked up pandas This should not be …
Groupby for value before previous row
How do i add a boolean if the value is lower than the value for the row above, per fruit? And if so the average of the previous 5 years Answer Try this: Output:
Pandas DataFrame – Filling a repeating null value with a preceding none-null value
How do I fill repeating null values with a preceding non-null value? For instance, the data frame above would be populated as: [‘a’,’a’,’a’,’b’,’b’,’b’] Answer Use df.fillna with the ffill method, as follows: Example:
Delete empty dataframes from a list with dataframes
This is a list of dataframes. I am trying to delete the empty dataframes from the above list that contains dataframes. Here is what I have tried: which gives: Important:It needs to store them in the data variable as well Answer We ca use filter or list comprehension
Change a column format while ignoring (or keeping) NaN
I want to change a column from a DataFrame which contains values of this format hh:mm:ss to a column containing the number of minutes (while keeping the NaN values) I can’t change it directly from the excel file so I’ve tried to do it with pandas (I’m working on a ML model with a health data…