Skip to content
Texxl

From junior to geek the road is sleek

operator

Ternary operator on pandas dataframe

November 19, 2021 by admin

Unfortunately you can use ternary operator like this a if x>y else b on pandas dataframe logic. With that said you can use numpy.where instead: df[‘result’] = np.where(df1[‘col1’] > df1[‘col2′], 1, 0) There you go. It’s also much faster.

Categories numpy, Pandas, Python Tags dataframe, numpy, operator, pandas, ternary, where

Categories

  • C#
  • Database
    • MariaDB
    • mySQL
  • git
  • Networking
    • Linux
    • nginx
    • Windows Server
  • Python
    • Anaconda
    • Cython
    • dask
    • Machine Learning
    • Numba
    • numpy
    • Pandas
    • plotly
  • Software
  • Uncategorized
  • Wordpress

Archives

  • June 2022 (1)
  • May 2022 (1)
  • February 2022 (4)
  • December 2021 (5)
  • November 2021 (15)
  • October 2021 (5)
  • September 2021 (1)
  • August 2021 (3)
  • July 2021 (1)
  • June 2021 (10)
  • May 2021 (8)
  • April 2021 (5)

Popular Posts:

  • Git clone only files without folder
  • Apply country inside python for loop
  • AttributeError: ‘float’ object has no attribute ’round’
  • Find out dataframe index value under a certain condition
  • Get actual value from pandas dataframe instead of object with index

9software.com - your one-stop software shop!

© 2022 Texxl • Built with GeneratePress