'Python 2.7 Pandas error with Data Frame and Dates

I have an application that runs daily. It gives sales scores and projections as the month goes on. For some reason one specific line, after years of working fine has started causing and error and for the life of me I cannot get it to work again. Here is an extract of the problematic area

#figure1
import pandas as pd
import datetime as dt
from calendar import monthrange
from bokeh.models import ColumnDataSource, Range1d, LabelSet, NumeralTickFormatter
from bokeh.plotting import figure
from bokeh.embed import components
from bokeh.resources import CDN

#Load Dataframes
df1 = pd.read_csv("data/CounterSales.csv")

#Set Variables
currentDate = dt.date.today()
thismonth = currentDate.month
thisyear = currentDate.year
thisday = currentDate.day
daysinmonth = monthrange(thisyear, thismonth)
monthsofyear = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
monthrage = Range1d(start=1, end=12)
#Create Figure 1
    def cs_figure1(storename):
        #plot1 Variables
        df1["Projection"] = round(df1["Total"] / thisday * daysinmonth[1], 0).astype("int")
        yMask = df1["TrnYear"] == thisyear
        mMask = df1["TrnMonth"] == thismonth
        sMask = df1["BranchName"] == storename

**The problematic bit seems to be this

    df1["Projection"] = round(df1["Total"] / thisday * daysinmonth[1],0).astype("int")

The error I get is

Serving Flask app "flapp" (lazy loading)
Environment: production
 WARNING: Do not use the development server in a production environment.
 Use a production WSGI server instead.
Debug mode: off
Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
[2022-02-23 12:19:40,395] ERROR in app: Exception on /upgrades [GET]
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1813, in full_dispatch_request
  rv = self.dispatch_request()
  File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "flapp.py", line 42, in upgrades
  plot1 = up_figure1(storename)
  File "/home/pi/sbproject/upgrades.py", line 26, in up_figure1

  **df1["Projection"] = round(df1["Total"] / thisday * daysinmonth[1], 0).astype("int")
  File "/home/pi/.local/lib/python2.7/site-packages/pandas/core/series.py", line 93, in         wrapper
    "{0}".format(str(converter)))
TypeError: cannot convert the series to <type 'float'>**

So it always worked, but now fails for the last few months.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source