Skip to content
Advertisement

Tag: dataframe

pandas not converting an object dtype to float64 even after error free execution of df.astype(‘float64’)

I have tried to convert an object dtype column to float64 using .astype(‘float64’) It ran without raising any error, but when I check the dtype using .dtype or .dtypes it is showing that converted column again as object. real_estate.dtypes Why is it not converting and why isn’t it giving any error? also, real_estate[‘Age at time of purchase’].dtype this is giving

How to vectorize pandas operation

I have a dataset of house sales with timestamped Periods(per quarter). I want to adjust the price according to the house pricing index change per region. I have a separate dataframe with 3 columns, the Quarter, the Region and the % change in price. I am currently achieving this by iterating over both dataframes. Is there a better way? Minimal

How to merge two dataframes and eliminate dupes

I am trying to merge two dataframes together. One has 1.5M rows and one has 15M rows. I was expecting the merged dataframe to haev 15M rows, but it actually has 178M rows!! I think my merge is doing some kind of Cartesian product, and this isn not what I want. This is what I tried, and got 178M rows.

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 function directly modifies my dataframe, something I am not sure I should be doing.

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 not an efficient solution at all. Are

Iterate through a dictionary and update dataframe values

i have a dictionary and a df column contains the country code “BHR”,”SAU”,”ARE”..etc how to update this column so if it find any of the dict keys it will create new column [“TIMEZONE”] row to the dict value. also add if statement that if the row is not equal to the key add a default value here is my try

Advertisement