Skip to content

Tag: pandas

Pandas split list upon DataFrame creation

I have a JSON file coming in, which I am doing some operations/trimming on. The result looks like this: When applying df = pd.DataFrame(user, index=[0]) I get the following Dataframe: When applying df = pd.DataFrame(user) I get: I am aware, as to why that happens, however none is what I want. I’d like t…

Looping through a second column using a probability input

I have a similar question to one I posed here, but subtly different as it includes an extra step to the process involving a probability: Using a Python pandas dataframe column as input to a loop through another column I’ve got two pandas dataframes: one has these variables Another is a table with these …

Compare variables through a range

I’ve 2 DataFrames where one gives me 3 Dates and a slope, and the other one gives me a calendar with prices. I’m want to know if any High price in Dates breaks the line between Date1 and Date3 of the slope_and_dates DataFrame. I expect an extra column in slopes_and_dates called Break where I can s…

Pandas: Is better aggregation possible

I have sample dataframe above. I wish to calculate percentage True for each date. I am able to do as below. But, feel it can be done with groupby + agg. Is it possible? My attempt: Answer You can do groupby like this: Output: You can get both percentages for T and F with crosstab: Output: Note 1: Extra commen…