2

I have a rainfall dataset with from 1970 to 2019 with Location, Y, M, D columns.

I can plot that with

ax = sns.lineplot(x="Month", y="Rainfall", hue="Year", data=df)

But I want the output plot to only be limited to certain years or location like because if I plot all the years according to hue, then it becomes a mess. Something like this,

ax = sns.lineplot(x="Month", y="Rainfall", hue="Dayofyear", data=df[(df.Station == 'Dhaka') & (df.Year == 1970])

but when I do that nothing happens.This is output https://i.stack.imgur.com/4KJmE.png

But when I set it like this (df.Year >= 1977), I get an output.

ax = sns.lineplot(x="Month", y="Rainfall", hue="Dayofyear", data=df[(df.Station == 'Dhaka') & (df.Year >= 1977)])

Like this : https://i.stack.imgur.com/kwWUU.png

Is there an easy way to specify the 'data' here. Like, I want to specify a range of years to show like 1970<year<1999 ?

CatVI
  • 45
  • 8

1 Answers1

1

IIUC use:

data=df[(df.Station == 'Dhaka') & (df.Year.betwen(1970, 1999, inclusive=False))]
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
  • when i use ax = sns.pointplot(x="Month", y="Rainfall", hue="Year", data=df[(df.Station == 'Dhaka') & (df.Year.between(1970, 1979, inclusive=False))], there is this error : SyntaxError: unexpected EOF while parsing – CatVI Aug 19 '20 at 08:05
  • @CatVI - there is missing last `)` need `ax = sns.lineplot(x="Month", y="Rainfall", hue="Dayofyear", data=df[(df.Station == 'Dhaka') & (df.Year.between(1970, 1979, inclusive=False))])` – jezrael Aug 19 '20 at 08:07
  • yes it worked. thank you very much! Also, if I want to specify exact year then what should I do? suppose I want to specify year 1990, 2004, and 2010. And data of station 'Dhaka' and 'London'. – CatVI Aug 19 '20 at 08:15
  • @CatVI - then use `isin`, like [this](https://stackoverflow.com/questions/19960077/how-to-filter-pandas-dataframe-using-in-and-not-in-like-in-sql) – jezrael Aug 19 '20 at 08:16