2

How do I transform this SQL code:

SELECT
   COUNT(DISTINCT DATEn) as count (*)
FROM weather_data
WHERE cast (rain as integer) = 1

using the Pandas notation, like this: df.groupby ('rain') DATEn.sum ()

MaxU - stand with Ukraine
  • 205,989
  • 36
  • 386
  • 419
Igor dias
  • 35
  • 3
  • Please read [how to make good reproducible pandas examples](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) and edit your post correspondingly. – MaxU - stand with Ukraine Oct 18 '17 at 22:28

1 Answers1

1

IIUC:

df.loc[pd.to_numeric(df['rain'], errors='coerce') == 1, 'DATEn'].nunique()
MaxU - stand with Ukraine
  • 205,989
  • 36
  • 386
  • 419
  • Thanks for the help, it worked. I was trying to filter the df ['rain'] and then use the groupby function to group the records by day and count the number of days, but it did not work out very well. – Igor dias Oct 18 '17 at 22:22
  • @Igordias, i have converted your SQL to Pandas - you didn't use `GROUP BY` clause, so that SQL should return one number, so my solution. ;-) Maybe you should open a new question with a new SQL, including `GROUP BY`... – MaxU - stand with Ukraine Oct 18 '17 at 22:24