用Pandas表示法转换SQL代码

时间:2017-10-18 22:12:14

标签: python sql pandas

如何转换此SQL代码:

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

使用熊猫符号,如下所示:df.groupby(' rain')DATEn.sum()

1 个答案:

答案 0 :(得分:1)

IIUC:

df.loc[pd.to_numeric(df['rain'], errors='coerce') == 1, 'DATEn'].nunique()