【问题标题】:Encoding field is specified without a type; the type cannot be automatically inferred because the data is not specified as a pandas.DataFrame未指定类型的编码字段;无法自动推断类型,因为数据未指定为 pandas.DataFrame
【发布时间】:2021-03-04 16:53:24
【问题描述】:

出现以下错误

raise ValueError("{} 指定编码字段没有类型;" ValueError: vipin 编码字段未指定类型;无法自动推断类型,因为数据未指定为 pandas.DataFrame。

import pyodbc
import altair as alt
import pandas as pd
connection = pyodbc.connect(Driver='{SQL Server};',
                            server='server\SQLEXPRESS',
                            Database='DB',
                            uid ='UID',
                            pwd='pwd',
                            # Trusted_Connection='yes;'
                            )
cursor = connection.cursor()
df = pd.read_sql_query(' SELECT distinct EDITWHO,EDITDate FROM ddd where editwho is not null ',connection);
print(df)
for item, row in df.iterrows():
    chart =alt.Chart(row).mark_bar().encode(
        x=row['EDITWHO'],
        y=row['EDITDate']
)
chart.save('chart.html')

【问题讨论】:

    标签: python python-3.x pandas altair


    【解决方案1】:

    Altair 接受 data 参数的数据帧和编码的列名。您正在为 data 参数传递一个系列,并为编码传递数据值。除了遍历行之外,您可能的意思是执行以下操作:

    chart = alt.Chart(df).mark_bar().encode(
      x='EDITWHO',
      y='EDITDate',
    )
    chart.save('chart.html')
    

    【讨论】:

      猜你喜欢
      • 2021-03-06
      • 1970-01-01
      • 2018-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多