Avatar ·

What does tilde mean in pandas?

📁 python

What does the tilde mean in this case?

df = df.loc[~non_numberic_profits]

In the non_numberic_profits column, strings were specified that do not match the float data type. That is, not numbers, but some letters or symbols.

What does the tilde mean in this case? What function does it perform?

After this line, the following line of code followed `

df.profit = df.profit.apply(pd.to_numeric)

As I understand it, it converts specifically to the float data type. But what does it convert? The remaining values? I don't quite understand what the tilde operator does in this case.

Avatar ·

Option 1:

a = a.rename(columns=lambda col: col.replace("" "", ""_""))

Option 2:

a.columns = a.columns.str.replace("" "", ""_"")

Option 3:

a.columns = a.columns.map(lambda x: x.replace("" "", ""_""))

Result:

In [8]: aOut[8]:   id  b First_Name

Log in to leave an answer

Blogs