Hello
I’m trying to output a list of solid volumes that contain empty values to Excel.
After some research, I found that the empty values are the cause of the problem.
So I thought I could replace the empty values with 0, but it didn’t work.
Do you know any solutions?
@shirai-a a one liner in python.
OUT = [0 if item == [] else item for item in IN[0]]
3 Likes
The bigger problem here is structure. You’re trying to replace a list with an item and that changes a lot more than just values. It would be more helpful if you could explain what data you’re trying to capture and how you expect missing values to be handled (is the 0 because you want to sum values or is it meant to represent a blank?)
The immediate “fix” is to replace your empty lists with a non-empty list (either with a 0 or empty string) before transposing, so that value ends up in the sublist at the right level. You’ll still need to flatten the sublists since one of your values is a list. The warning from OpenXML is because you have a list where there should be an item.
4 Likes
A solution with pandas (clean data + export to excel)
import sys
import clr
import os
import pandas as pd
import openpyxl as xl
columns = IN[0]
data = IN[1]
xl_file_path = IN[2]
df = pd.DataFrame(data=data, columns=columns)
# replace list by 0 value
df["Volume"] = df["Volume"].apply(lambda y: 0 if type(y) is list else y)
df.to_excel(xl_file_path, sheet_name='Sheet1', index=False)
os.startfile(xl_file_path)
OUT = xl_file_path, repr(df)
3 Likes
Dynamo freezes when I try to edit a python script. Is this normal?
I believe it’s the time it takes for the python engine to initialize
it freeze and crash or just freeze some seconds?
i’ve noticed a couple of seconds of freezes when creating a python node. long freeze? not normal.
It would freeze for a long time and then crash.
But after a while, it worked again.
I solved it with your Python script. Thank you.
It would freeze for a long time and then crash.
But after a while, it worked again.