Python 3 寻找低雨天数序列

2024-09-27 21:32:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个365行的数据帧,我想得到一个开始日期,时间范围和降雨量小于一个特定值(干旱)

示例:

 PRODUKT_CODE  STATION_ID   Ppt  QN  QB
ZEITSTEMPEL
2018-01-01      RS_MN006        1055  27.4   3   0
2018-01-02      RS_MN006        1055  28.1   3   0
2018-01-03      RS_MN006        1055   9.3   3   0
2018-01-04      RS_MN006        1055   7.8   3   0
2018-01-05      RS_MN006        1055   4.7   3   0
2018-01-06      RS_MN006        1055   5.3   3   0
2018-01-07      RS_MN006        1055   1.0   3   0
2018-01-08      RS_MN006        1055   0.0   3   0
2018-01-09      RS_MN006        1055   0.5   3   0
2018-01-10      RS_MN006        1055   2.1   3   0
2018-01-11      RS_MN006        1055   0.6   3   0
2018-01-12      RS_MN006        1055   0.0   3   0

我试着用这个环

df_1["Value"] = 0
for i in np.arange(df_1["Ppt"].count()-3):
    if df_1["Ppt"][i]>10:
        if df_1["Ppt"][i+1] < 2 and df_1["Ppt"][i+2] < 2 and df_1["Ppt"][i+3] <2:
            df_1["Value"][i]=1
            print("Sequence of days were found at: "+ str(df_1["Ppt"].index[i]))
            print("Ppt for day 1 :", + str(df_1["Ppt"][i] + "Ppt for day 2,3,4:" + str(df_1["Ppt"][i+1]) + " " + str(df_1["Ppt"][i+2]) + " " + str(df_1["Ppt"][i+3])))

但最后却犯了这个错误

C:\Users\USER\Desktop\Masterarbeit\2 CODE\radolan\Rainall_analysis.py:31: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  df_1["Value"][i]=1
Sequence of days were found at: 2018-01-25 00:00:00
Traceback (most recent call last):
  File "C:\Users\USER\Desktop\Masterarbeit\2 CODE\radolan\Rainall_analysis.py", line 33, in <module>
    print("Ppt for day 1 :", + str(df_1["Ppt"][i] + "Ppt for day 2,3,4:" + str(df_1["Ppt"][i+1]) + " " + str(df_1["Ppt"][i+2]) + " " + str(df_1["Ppt"][i+3])))
TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('<U32') dtype('<U32') dtype('<U32')

有没有一个优雅的方法或者一个功能模块来分析每天的降水数据?你知道吗


Tags: of数据indfforvaluecodeprint

热门问题