Monday, April 17, 2017

Python Pandas Dataframe - Where Condition Example

Here is an example on using Where condition on pandas dataframe.
Census data used as source.


Use Case : 


  • Read Population data for state of California from "censusdata.ire.org" URL.
  • Get Counties with population more than 1000000.



Syntax : 


DataFrame.where()



Main Parameters :


condition : 

     Condition should return boolean.


inplace :

    Whether to perform the operation in place
  •  
raise_on_error :
  •     Raise error on invalid data types



Sample Code


import pandas as pd
df = pd.read_csv("http://censusdata.ire.org/06/all_050_in_06.P1.csv")
df = df[["NAME","POP100"]]
df.where(df["POP100"] > 1000000).dropna(how='all')

Sample Output



1 comment:

  1. Elegant Dating Call Girls in Aerocity: You can feel like you are on cloud nine by sleeping with a dazzling adult partner.Nepali Call Girls in Ahmedabad She behaves in such a way that you are her boyfriend.Nepali Call Girls in Ahmedabad Just hire one of the sensational escorts in Haridwar with us and ensure to spend unforgettable moments with her body.Low Rate Escorts in Haridwar The fun of adult entertainment is something that would arouse your physical needs and make you cherish astonishing memories.Low Rate Escorts in Delhi It is not all about all feeling well with a gorgeous adult partner but more than that.Low Rate Escorts in Ahmedabad You will get enough time to enjoy some incredible sensuous activities and relish the extreme sensuous satisfaction.

    ReplyDelete