没有指定类型的编码字段;无法自动推断类型,因为数据未指定为 pandas.DataFrame
Encoding field is specified without a type; the type cannot be automatically inferred because the data is not specified as a pandas.DataFrame
出现跟随错误
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')
Altair 接受数据帧作为数据参数,接受列名作为编码。您正在为数据参数传递一个系列,并为编码传递数据值。 Intead 遍历行,你可能想做这样的事情:
chart = alt.Chart(df).mark_bar().encode(
x='EDITWHO',
y='EDITDate',
)
chart.save('chart.html')
出现跟随错误
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')
Altair 接受数据帧作为数据参数,接受列名作为编码。您正在为数据参数传递一个系列,并为编码传递数据值。 Intead 遍历行,你可能想做这样的事情:
chart = alt.Chart(df).mark_bar().encode(
x='EDITWHO',
y='EDITDate',
)
chart.save('chart.html')