Fundamentals 2 min read

Fixing Empty Charts in Pyecharts When Using Pandas DataFrames

This article explains why passing pandas data directly to Pyecharts results in blank charts due to NumPy data types, and shows how converting pandas Series to Python lists with .tolist() resolves the issue, providing corrected example code.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Fixing Empty Charts in Pyecharts When Using Pandas DataFrames

When passing a pandas DataFrame directly to Pyecharts, the chart may appear blank with only axes because pandas uses NumPy data types such as numpy.int64 and numpy.float64 , which Pyecharts does not handle specially.

The article demonstrates the issue with a sample DataFrame containing brand names and sales numbers, shows the resulting empty chart, and prints the type of a series element to illustrate the NumPy type.

df = pd.DataFrame(dict(Brand=['Apple','Huawei','Xiaomi','Oppo','Vivo','Meizu'], sales=[123,153,89,107,98,23]))
bar = (Bar()
       .add_xaxis(df['Brand'])
       .add_yaxis('', df['sales']))
bar.render_notebook()

To resolve the problem, convert the pandas Series to a plain Python list using the .tolist() method before supplying the data to Pyecharts. The corrected code creates the DataFrame, calls df['Brand'].tolist() and df['sales'].tolist() for the x‑axis and y‑axis, and renders the chart successfully.

df = pd.DataFrame(dict(Brand=['Apple','Huawei','Xiaomi','Oppo','Vivo','Meizu'], sales=[123,153,89,107,98,23]))
bar = (Bar()
       .add_xaxis(df['Brand'].tolist())
       .add_yaxis('', df['sales'].tolist()))
bar.render_notebook()
data-visualizationpandastype conversionpyecharts
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.