【发布时间】:2021-10-19 04:15:25
【问题描述】:
我正在尝试构建一个精简的应用程序。下面是我正在尝试的工作示例
from pm4py.objects.conversion.log import converter as log_converter
import pandas as pd
import pm4py
df = pm4py.format_dataframe(pd.read_csv('https://raw.githubusercontent.com/pm4py/pm4py-core/release/notebooks/data/running_example.csv', sep=';'), case_id='case_id',activity_key='activity',
timestamp_key='timestamp')
log = log_converter.apply(df)
precedence_dict = pm4py.discover_dfg(log)[0]
precedence_dict 是(前件,后件)和计数的字典
precedence_dict = {('check ticket', 'decide'): 6,
('check ticket', 'examine casually'): 2,
('check ticket', 'examine thoroughly'): 1,
('decide', 'pay compensation'): 3,
('decide', 'reinitiate request'): 3,
('decide', 'reject request'): 3,
('examine casually', 'check ticket'): 4,
('examine casually', 'decide'): 2,
('examine thoroughly', 'check ticket'): 2,
('examine thoroughly', 'decide'): 1,
('register request', 'check ticket'): 2,
('register request', 'examine casually'): 3,
('register request', 'examine thoroughly'): 1,
('reinitiate request', 'check ticket'): 1,
('reinitiate request', 'examine casually'): 1,
('reinitiate request', 'examine thoroughly'): 1
}
将上述 dict 转换为 pandas 数据帧
precedence_df = pd.DataFrame.from_dict(precedence_dict, orient='index').reset_index()
rename_map = {"index" : "Antecedent,Consequent", 0 : "Count"}
precedence_df = precedence_df.rename(columns=rename_map)
precedence_df['Antecedent'], precedence_df['Consequent'] = zip(*precedence_df["Antecedent,Consequent"])
# precedence_df.assign(**dict(zip(['Antecedent', 'Consequent'], precedence_df["Antecedent,Consequent"].str)))
# precedence_df['Antecedent'], precedence_df['Consequent'] = precedence_df["Antecedent,Consequent"].str
precedence_mat = precedence_df[['Antecedent', 'Consequent', 'Count']]
st.dataframe(precedence_df)
在此行运行应用程序时出现 ArrowInvalid 错误
完整的错误回溯
ArrowInvalid: ("Could not convert (x, y) with type tuple: did not recognize Python value type when inferring an Arrow data type", 'Conversion failed for column Antecedent, Consequent with type object')
Traceback:
File "C:\Users\zz\Documents\Streamlit\preced\app.py", line 1353, in <module>
st.dataframe(precedence_df)
File "c:\users\zz\anaconda3\lib\site-packages\streamlit\elements\dataframe_selector.py", line 85, in dataframe
return self.dg._arrow_dataframe(data, width, height)
File "c:\users\zz\anaconda3\lib\site-packages\streamlit\elements\arrow.py", line 82, in _arrow_dataframe
marshall(proto, data, default_uuid)
File "c:\users\zz\anaconda3\lib\site-packages\streamlit\elements\arrow.py", line 160, in marshall
proto.data = type_util.data_frame_to_bytes(df)
File "c:\users\zz\anaconda3\lib\site-packages\streamlit\type_util.py", line 371, in data_frame_to_bytes
table = pa.Table.from_pandas(df)
File "pyarrow\table.pxi", line 1561, in pyarrow.lib.Table.from_pandas
File "c:\users\zz\anaconda3\lib\site-packages\pyarrow\pandas_compat.py", line 595, in dataframe_to_arrays
for c, f in zip(columns_to_convert, convert_fields)]
File "c:\users\zz\anaconda3\lib\site-packages\pyarrow\pandas_compat.py", line 595, in <listcomp>
for c, f in zip(columns_to_convert, convert_fields)]
File "c:\users\zz\anaconda3\lib\site-packages\pyarrow\pandas_compat.py", line 581, in convert_column
raise e
File "c:\users\zz\anaconda3\lib\site-packages\pyarrow\pandas_compat.py", line 575, in convert_column
result = pa.array(col, type=type_, from_pandas=True, safe=safe)
File "pyarrow\array.pxi", line 302, in pyarrow.lib.array
File "pyarrow\array.pxi", line 83, in pyarrow.lib._ndarray_to_array
File "pyarrow\error.pxi", line 99, in pyarrow.lib.check_status
当前 pyarrow 版本 5.0.0。
当我尝试在 colab 中运行相同的代码(期望 st.dataframe)时,我没有任何问题/错误,我没有任何问题/错误。 ArrowInavlid Error 是什么意思,如何解决这个错误?
【问题讨论】:
标签: python pandas traceback pyarrow streamlit