Python Forum

Full Version: Replacing "." in columns
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys,

I got a data set with missing values, however, those cells contain a "." instead of being empty. Here is an example :

[Image: YPsYKvz]

I want to resample the data to weeks with

df = df.resample('1W').mean()
But this gives me the error :
DataError: No numeric types to aggregate

I guess I have to replace the cells, but I don't know with what and moreover, I do know how replace the string "." in the column, but this will also replace the other already existing values. I appreciate any help!

Edit : I tried the following :

for i in range(len(df5["x"])):
    if df5["x"][i].isnumeric() is False:
        df5["x"][i] = df5["x][i].replace(".","")
    else:
        pass
But this still replaces all "."
This is due to the way GroupBy objects handle the different aggregation methods. In fact sum and mean are handled differently. GroupBy.mean dispatches to self._cython_agg_general which checks for numeric types and in case it doesn't find any it raises a DataError.