Thursday, September 1, 2022

[SOLVED] Python code works on JupyterNotebook (local) but not on Visual Studio Code (ssh)

Issue

So, I have a piece of code written in Python which works perfectly fine on my local Jupyter Notebook, BUT when I run the same piece of code on Visual Studio Code it doesn't work.

This is the code:

for i in df.index:
        for j in columns:

            millis = round(int(df.loc[i, j].value / 1e+6))
            millis = np.array([millis])

            for x in millis:

                seconds = (x/1000)%60
                seconds = int(seconds)

                minutes = (x/(1000*60))%60
                minutes = int(minutes)

                hours = (x/(1000*60*60))%24

                hour = "%d:%d:%d" % (hours, minutes, seconds)

                df.loc[i,j] = hour

So, this is to turn previously converted columns from timedelta to it's original values.

Everything works fine until the last line df.loc[i, j] = hour

For some strange reason, it works fine on my local Jupyter Notebook but that particular line doesn't work on Visual Studio Code.


Solution

It was a problem with pandas version. Super weird! Can't believe a simple dataframe.loc won't work on a version a it did on other version



Answered By - Milton De Marte
Answer Checked By - Mary Flores (WPSolving Volunteer)