Python Forum
Search Results
Post Author Forum Replies Views Posted [asc]
    Thread: Pandas dataframe: calculate metrics by year
Post: RE: Pandas dataframe: calculate metrics by year

This will work! import numpy as np import pandas as pd from sklearn.metrics import r2_score, mean_squared_error def r2_rmse( g ): r2 = r2_score( g['Actual'], g['Predicted'] ) rmse = np.sqrt(...
mcva Data Science 1 2,327 Mar-02-2022, 08:22 AM
    Thread: Pandas dataframe: calculate metrics by year
Post: Pandas dataframe: calculate metrics by year

Hi I have some dataframes with a very diferent number of years , similar to the following dataframe: Date obs sim 6/12/2000 22.32 14.6 8/11/2000 19.82 13.4 10/10/2000 16.63 16.7 2/14/2001 11.92 14.8...
mcva Data Science 1 2,327 Mar-01-2022, 12:30 PM
    Thread: Save data frame to .csv df.to.csv()
Post: RE: Save data frame to .csv df.to.csv()

I have found this solution. Replacing the last line with: df.to_csv(f'Station_{index+1}.csv')I will get: Station_1.csv Station_2.csv It is not perfect because I still can´t use the name that is ...
mcva General Coding Help 1 1,535 Feb-03-2022, 07:05 PM
    Thread: Save data frame to .csv df.to.csv()
Post: Save data frame to .csv df.to.csv()

Hi everyone I need to write a .csv file at each iteration of the following loop. I need to change the name of the .csv file at each iteration. The name of the file at each iteration is stored in the ...
mcva General Coding Help 1 1,535 Feb-03-2022, 11:48 AM
    Thread: Why is this Python code running twice?
Post: RE: Why is this Python code running twice?

(Jan-31-2022, 08:05 PM)deanhystad Wrote: dt should not have a repeat, but I like to be sure. I would print something at the start of the script (print("Hi Mom")). If you see that twice it would me...
mcva General Coding Help 5 5,288 Feb-02-2022, 10:21 AM
    Thread: Why is this Python code running twice?
Post: RE: Why is this Python code running twice?

(Jan-31-2022, 03:34 PM)buran Wrote: what is convert_nc_to_csv1 and what is its content? And how do you know it runs twice? Hi convert_nc_to_csv1 is another .py file with the value of those two vari...
mcva General Coding Help 5 5,288 Jan-31-2022, 03:48 PM
    Thread: Why is this Python code running twice?
Post: Why is this Python code running twice?

Hi everybody Why is this code running twice? Is this related with the variables that the code imports from convert_nc_to_csv1? Thank you. # Reading the netcdf file from netCDF4 import Dataset import...
mcva General Coding Help 5 5,288 Jan-31-2022, 03:09 PM
    Thread: Increase the speed of a python loop over a pandas dataframe
Post: Increase the speed of a python loop over a pandas ...

Hi I´m using the following code to fill a dataframe with values that are stored in a .nc file This code is quite slow. The speed can be improved with list comprehensions? If the answer is yes, can y...
mcva General Coding Help 0 1,321 Jan-21-2022, 06:24 PM
    Thread: Simple pandas question
Post: RE: Simple pandas question

This is a good solution... import pandas as pd import numpy as np # Import data data = pd.read_excel('moving_average.xlsx', index_col=0, header=0) results = [] for i in range(100): tmp = data.r...
mcva Data Science 4 2,659 Dec-17-2021, 04:47 PM
    Thread: Simple pandas question
Post: RE: Simple pandas question

(Nov-30-2021, 03:13 AM)jefsummers Wrote: Yes, a bit messy and I am sure can be simplified, but it is unclear to me what you want to do. Can you explain better (words, I see the code)? I have a dataf...
mcva Data Science 4 2,659 Nov-30-2021, 02:15 PM
    Thread: Simple pandas question
Post: Simple pandas question

I´m using the following code to estimate the moving average for each column (year X) of a dataframe considering a window (pandas.DataFrame.rolling first parameter) that varies from 1 to 100. The code...
mcva Data Science 4 2,659 Nov-25-2021, 12:26 PM
    Thread: Scipy kolmogorov smirnov test for evaluating the fitting of a non-normal distribution
Post: Scipy kolmogorov smirnov test for evaluating the f...

Hi thank you in advance for reading this Can Scipy kolmogorov smirnov (KS) test be used for evaluating the fitting of a non-normal distribution like the Exponnorm, to a continuous variable? My obser...
mcva General Coding Help 0 1,993 May-26-2020, 12:01 PM
    Thread: How can I convert specific rows from excel to pandas dataframe?
Post: How can I convert specific rows from excel to pand...

Hello, I have some excel work sheets files that have this type of format (7400 groups of rows separated by two rows: "TEMP 25" and "1 Jan 1, 1989 6 -0.0398 1") TEMP 25 10 20 30 12 2 50 66 5...
mcva Homework 1 1,807 Apr-19-2020, 03:38 PM
    Thread: Pandas resample problem
Post: Pandas resample problem

Thank you for your help. I have a time series dataframe with hourly data distributed over a 20 years period (N = 175297): Data A B C D 1/1/1989 0:00 12.0000 12.0000 12.0000...
mcva Homework 0 1,406 Nov-29-2019, 04:21 PM
    Thread: How can I run a function inside a loop every 24 values of the loop iteration range?
Post: How can I run a function inside a loop every 24 va...

How can I run a function inside a loop every 24 values of the loop iteration range? I only want to TempLake[i]=fix_profile(Nlayers,TempTDMA,Areat0) every 24 values, else I want TempLake[i]=TempTDMA ...
mcva Homework 1 2,139 Sep-18-2019, 04:27 PM
    Thread: Nested for loop strange problem
Post: RE: Nested for loop strange problem

(Mar-16-2019, 12:51 PM)Yoriz Wrote: The function fix_profile must be altering something that the rest of the code is dependant on. No one else can understand the code that has been presented. Its no...
mcva General Coding Help 2 2,621 Mar-16-2019, 12:53 PM
    Thread: Nested for loop strange problem
Post: Nested for loop strange problem

Thank you for taking some time to read this problem... I have this nested for loop and I´m note sure its doing what I need. I need to run a lake temperature model for N = 365 and for each day (i) the ...
mcva General Coding Help 2 2,621 Mar-16-2019, 12:22 PM
    Thread: Converting R code to python
Post: RE: Converting R code to python

You are right, Thank you so much,
mcva General Coding Help 2 12,536 Mar-09-2019, 04:01 PM
    Thread: Converting R code to python
Post: Converting R code to python

I´m trying to convert the following R code to python but theres something wrong with my code results are not the same can you take a look at it? Thank you. With this input vector or list: wtr = c(1,1...
mcva General Coding Help 2 12,536 Mar-09-2019, 01:28 PM

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020