I was wondering how to highlight diagonal elements of pandas dataframe using df.style method. I found this official link where they discuss how to highlight maximum value, but I am having difficulty creating function to highlight the diagonal elements. Here is an example: This gives following output: I am wan…
Tag: pandas
Find columns where at least one row contains an alphabetical letter
Let’s say I have the following data set: I would like to find out – without any cumbersome for loop – which columns contain at least one case with an alphabetical letter (here: B and C). I guess the result should either be a list of booleans or indices. Thank you for your help! Answer As a q…
remove special characters and string from df columns in python
Currently my column is of object type and I’m trying to convert it to type numeric. But it shows the error because of special characters and string contained in it. error: code: So, I want to remove the special char and string from the columns that requires only number and col1 being one of it. Any sugg…
Extracting codes with regex (irregular regex keys)
I´m extracting the codes from a string list using coming from the title email. Which looks something like: So far what I tried is: My issue is that, I´m not able to extract the code next to the words that goes before [‘PN’, ‘P/N’, ‘PN:’, ‘P/N:’], specially if th…
Is there a way to visualise time series data in such a way that on x-axis i get ticks in year-month format in python?
I am trying to plot a data of stock close price for each day but on the x-axis, i get no labels on xtick instead of year-month format I tried to take the “Date” and “Close Price” column in a separate dataframe and then tried plotting them. I have dataframe similar to this Answer Just c…
Dataframe how to update a column based many str values
I am creating a small financial management program which imports my transactions from CSV into Python. I want to assign values to a new column ‘category’ based on strings found in the ‘details’ column. I can do it for one, but my question is how do I do it if I had a huge list of possi…
Imbalanced-Learn’s FunctionSampler throws ValueError
I want to use the class FunctionSampler from imblearn to create my own custom class for resampling my dataset. I have a one-dimensional feature Series containing paths for each subject and a label Series containing the labels for each subject. Both come from a pd.DataFrame. I know that I have to reshape the f…
How to create a Pandas DataFrame from dictionary of dataframes?
I have a dictionary that is a list of dataframes that have all the same columns and data structure. I am wanting to essentially ‘union’ all of these into a single dataframe again, where the dictionary keys are converted into another column: df_list{} …and so on but am wanting: I tried using …
Pandas: How to read CSV file from google drive public?
I searched similar questions about reading csv from URL but I could not find a way to read csv file from google drive csv file. My attempt: How can we read this file in pandas? Related links: Pandas read_csv from url https://pandas.pydata.org/pandas-docs/version/0.22/io.html#io-read-html Answer Using pandas U…
Specify ordering for columns when creating a DataFrame from list of dictionaries
I have a method that creates a list, results, and then appends to it a dict row which has keys (column names in my eventual dataframe) and values (row values in my eventual dataframe). Then I append the row and convert the results collection to a df at the end. For example: The issue I have is that the column