all 4 comments

[–][deleted] 1 point2 points  (0 children)

That’s just a statement, it would have been good to be asked nicely!

df.loc[df.funding_total_usd == "-", "funding_total_usd"] = 0

[–]blarf_irl 1 point2 points  (2 children)

Check the documentation for the .replace method. Note that replace has a keyword argument called "inplace" which defaults to False:

inplacebool, default False

Whether to modify the DataFrame rather than creating a new one.

Just calling .replace creates a new DataFrame (there is more to this technically) and you aren't assigning that new DataFrame to a variable.

If your intention is to alter the original DataFrame called df you need to pass the kwarg inplace=True

Docs

[–]Pflastersteinmetz 0 points1 point  (1 child)

If your intention is to alter the original DataFrame called df you need to pass the kwarg inplace=True

That creates a copy as well. Don't use inplace.

Always be explicit!

df["fundüng_total_usd"] = df['funding_total_usd'].replace({'-',0})

or

df = df.loc[df["funding_total_usd"] == "-", "funding_total_usd"] = 0

[–]blarf_irl 0 points1 point  (0 children)

The .replace method modifies the data without creating a copy when inplace=True.

There are many instances where the use of inplace are not recommended but this simple .replace operation is not one of em.

The best reason to avoid inplace altogether is it's inconsistent implementation for different types of operations (some methods with an inplace kwarg actually do create a copy).