python 3 find sequence of days with low rainfall












0















I have a 365 row dataframe and i want to get a start date, time range and a amount of rainfall less than a specific value (drought )



example:



 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


i try it with this loop



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])))


but end up with this error



C:UsersUSERDesktopMasterarbeit2 CODEradolanRainall_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:UsersUSERDesktopMasterarbeit2 CODEradolanRainall_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')


is there an elegant way or maybe a module with functions to analyse precipitation data on a daily base?










share|improve this question


















  • 1





    It would help if you provided a Minimal, Complete, and Verifiable example that creates exactly the dataframe you are working with - and describe your "expected" output and what a "drought" is defined by.

    – Patrick Artner
    Jan 2 at 1:08






  • 1





    There is a comma in your second print statement, right after "Ppt for day 1 :", that looks like a typo and could trigger this error.

    – hlg
    Jan 2 at 1:42


















0















I have a 365 row dataframe and i want to get a start date, time range and a amount of rainfall less than a specific value (drought )



example:



 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


i try it with this loop



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])))


but end up with this error



C:UsersUSERDesktopMasterarbeit2 CODEradolanRainall_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:UsersUSERDesktopMasterarbeit2 CODEradolanRainall_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')


is there an elegant way or maybe a module with functions to analyse precipitation data on a daily base?










share|improve this question


















  • 1





    It would help if you provided a Minimal, Complete, and Verifiable example that creates exactly the dataframe you are working with - and describe your "expected" output and what a "drought" is defined by.

    – Patrick Artner
    Jan 2 at 1:08






  • 1





    There is a comma in your second print statement, right after "Ppt for day 1 :", that looks like a typo and could trigger this error.

    – hlg
    Jan 2 at 1:42
















0












0








0








I have a 365 row dataframe and i want to get a start date, time range and a amount of rainfall less than a specific value (drought )



example:



 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


i try it with this loop



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])))


but end up with this error



C:UsersUSERDesktopMasterarbeit2 CODEradolanRainall_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:UsersUSERDesktopMasterarbeit2 CODEradolanRainall_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')


is there an elegant way or maybe a module with functions to analyse precipitation data on a daily base?










share|improve this question














I have a 365 row dataframe and i want to get a start date, time range and a amount of rainfall less than a specific value (drought )



example:



 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


i try it with this loop



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])))


but end up with this error



C:UsersUSERDesktopMasterarbeit2 CODEradolanRainall_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:UsersUSERDesktopMasterarbeit2 CODEradolanRainall_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')


is there an elegant way or maybe a module with functions to analyse precipitation data on a daily base?







python pandas numpy






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 2 at 1:01









till Kadabratill Kadabra

376




376








  • 1





    It would help if you provided a Minimal, Complete, and Verifiable example that creates exactly the dataframe you are working with - and describe your "expected" output and what a "drought" is defined by.

    – Patrick Artner
    Jan 2 at 1:08






  • 1





    There is a comma in your second print statement, right after "Ppt for day 1 :", that looks like a typo and could trigger this error.

    – hlg
    Jan 2 at 1:42
















  • 1





    It would help if you provided a Minimal, Complete, and Verifiable example that creates exactly the dataframe you are working with - and describe your "expected" output and what a "drought" is defined by.

    – Patrick Artner
    Jan 2 at 1:08






  • 1





    There is a comma in your second print statement, right after "Ppt for day 1 :", that looks like a typo and could trigger this error.

    – hlg
    Jan 2 at 1:42










1




1





It would help if you provided a Minimal, Complete, and Verifiable example that creates exactly the dataframe you are working with - and describe your "expected" output and what a "drought" is defined by.

– Patrick Artner
Jan 2 at 1:08





It would help if you provided a Minimal, Complete, and Verifiable example that creates exactly the dataframe you are working with - and describe your "expected" output and what a "drought" is defined by.

– Patrick Artner
Jan 2 at 1:08




1




1





There is a comma in your second print statement, right after "Ppt for day 1 :", that looks like a typo and could trigger this error.

– hlg
Jan 2 at 1:42







There is a comma in your second print statement, right after "Ppt for day 1 :", that looks like a typo and could trigger this error.

– hlg
Jan 2 at 1:42














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54000165%2fpython-3-find-sequence-of-days-with-low-rainfall%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54000165%2fpython-3-find-sequence-of-days-with-low-rainfall%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Angular Downloading a file using contenturl with Basic Authentication

Olmecas

Can't read property showImagePicker of undefined in react native iOS