Subseting the DataFrame


2 Answer(s)


HI Gaurav,

I do not see "Unique" in the Station column, so I assume that to select rows whose station is CYPRESS HILLS and whose fog is 1, you can use the following code

import pandas as pd

file = pd.read_csv("turnstile_weather_v2.csv")

file.loc[(file.station=="CYPRESS HILLS")&(survery.fog==1)]

Hope this helps, 


 

import os

import numpy as np

import pandas as pd

file name = "C:/Users/SJAMEEL6/Downloads/turnstile_weather_v2.csv"

weatherDF = pd.read_csv(fileName)

weatherDF.head()

in station column i see "1 AVE" not 1 so based on your criteria you can change further.

Different ways we can filter / condition criteria:

Type 1:

SubsetData = weatherDF[(weatherDF.station == "1 AVE") & (weatherDF.fog == 1)]

Type 2:

SubsetData = weatherDF.loc[(weatherDF.station == "1 AVE") & (weatherDF.fog == 1) , ['station','fog'])

Type 3:

SubsetData = weatherDF.query('station == "1 AVE" and fog == 1')

 

Hope it serve your purpose