Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
314mp_M0th4
Resolver I
Resolver I

Python visual script handling dates as strings

Hello, I'm trying to insert a python visual I created (and works outside power BI), and insert into a power bi python visual. This is a gantt chart. When I try to run it it gives me the following error message:

 

Error Message:
Python script error.
TypeError: unsupported operand type(s) for -: 'str' and 'str'

During handling of the above exception, another exception occurred:

TypeError: unsupported operand type(s) for -: 'str' and 'str'

 

I suspect it is treating the date columns as a string. In the data model however, the dates are formatted as short dates and have the data type date. Can anyone explain what might be happening?

 

A piece of the code where i expect the error to be happening:

today = pd.Timestamp.today()
year_from_today = today + datetime.timedelta(days = 365)
proj_start = df["Verkefni hefst"].min()
df["start_num"] = (df["Verkefni hefst"] - proj_start).dt.days
df['end_num'] = (df["Verkefni lýkur"]-proj_start).dt.days
# days between start and current progression of each task
df['current_num'] = (df['Dagar í verkefni'] * df.Lokið)
df['days_start_to_end'] = df.end_num - df.start_num
 
Many thanks in advance!
1 ACCEPTED SOLUTION
314mp_M0th4
Resolver I
Resolver I

My bad, I realized that doing data editing is not wise inside the python script. You should edit the data in the ways you need with dax calculations and then feed those into the python visual!

View solution in original post

1 REPLY 1
314mp_M0th4
Resolver I
Resolver I

My bad, I realized that doing data editing is not wise inside the python script. You should edit the data in the ways you need with dax calculations and then feed those into the python visual!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.