аватар question@mail.ru · 01.01.1970 03:00

What does Tilda mean in Pandas?

What does Tilda mean in this case?

  df.loc [~ non_numberic_profits]     

in the Stolbets non_numberic_profits Lines were set that do not meet the type of data float . That is, not numbers, but some letters or symbols.

What does Tilda mean in this case? What function does it perform?

after this time, the following line of code

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

as I understand it, it transforms it precisely into the data type float . But what does she transform? The remaining values? I do not quite understand what the operator Tilda performs in this case.

аватар answer@mail.ru · 01.01.1970 03:00

This is an operation not , which is often used to invert logical columns/meanings.

:

Another Common Operation Is the Use of Boolean Vectors to Filter Data. The Operators are: | for or, & amp; for and, and ~ for not.

  in [ 475 ]: s = pd.series (np.random.choice ([ true ,  false ], size =  5 )) in [ 476 ]: sout [ 476 ]:   0   true    1   true    2   false    3   true    4   trye  dtype:  bool  in [ 477 ]: ~ sout [ 477 ]:   0   false    1   false    2   true    3   false    4   false  dtype:  bool   

upd: what is the command df.loc [~ non_numberic_profits]

this command The frames filter the frame in such a way that only those lines of the frame are selected for which in the corresponding position non_numberic_profits is the value of false

note: the length of the non_numberic_profits must coincide with the length (number of lines) df

.


upd2: What is the command df.profit = df.profit.apply (pd.to_numeric) :

This is not a very effective way to convert all the column values ​​to the numerical type of data int64 or float64

it is better to do this So:

  df [ "propan>] = pd.to_numeric (df [ "" Profit "" ], errors =  "" coerce "" )                                       

Latest

Similar