Skip to content

Tag: pandas

Adding to a nested Dictionary in a Column in Pandas

So, I have a fun issue. I have some data that have a fun nested dictionary that I need to manipulate, but am having trouble. I can do it in pure python, but wanted to do the entire solution in Pandas so as to keep the code a little cleaner and not have to re-open the same files elsewhere. Dataframe:

Conditional counts in pandas group by

I have the following dataframe I want to reformat it in the following way: Group by name/account/monthly periods Average (mean) balance to two decimal places Average (mean) for transactions to no decimal places Count of days where balance < 0 Count of days where Balance > Max credit So the I apply the f…

How do I separate this dataframe column by month?

A few rows of my dataframe The third column shows the time of completion of my data. Ideally, I’d want the second row to just show the date, removing the second half of the elements, but I’m not sure how to change the elements. I was able to change the (second) column of strings into a column of f…

comma seperation for each cell of dataframe pandas

If there are any cells with a comma (if condition), I would like to separate them out and pick the last one, something like: The original table is like here below: index x1 x2 0 banana orange 1 grapes, Citrus apples 2 tangerine, tangerine melons, pears which is going to be changed to like below: index x1 x2 0…

find days between 2 dates in python but only number

I was trying to find difference of a series of dates and a date. for example, the series is from may1 to june1 which is the only thing i could get is this. I don’t want anything other than the number 1-10 cuz i need them for further numerical calculation but i can’t get rid of those. Also how coul…

how to perform string formatting inside a dictionary?

lets say i have a payload which i am using to hit my API but i wanted to make its pg_no value as dynamic using for loop i.e. getting this error Answer first in your dictionary you are using same key from_data which is gonna be only last one present there. second main problem is causing by { bracket format