If someone could help me with this rather uninformative error

Traceback (most recent call last):
  File "run_me.py", line 142, in <module>
    fig = px.scatter_3d(
          ^^^^^^^^^^^^^^
  File "plotly\express\_chart_types.py", line 776, in scatter_3d
    return make_figure(args=locals(), constructor=go.Scatter3d)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "plotly\express\_core.py", line 2076, in make_figure
    args = build_dataframe(args, constructor)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "plotly\express\_core.py", line 1341, in build_dataframe
    args["data_frame"] = pd.DataFrame(args["data_frame"])
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pandas\core\frame.py", line 737, in __init__
    mgr = dict_to_mgr(data, index, columns, dtype=dtype, copy=copy, typ=manager)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pandas\core\internals\construction.py", line 503, in dict_to_mgr
    return arrays_to_mgr(arrays, columns, index, dtype=dtype, typ=typ, consolidate=copy)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pandas\core\internals\construction.py", line 114, in arrays_to_mgr
    index = _extract_index(arrays)
            ^^^^^^^^^^^^^^^^^^^^^^
  File "pandas\core\internals\construction.py", line 677, in _extract_index
    raise ValueError("All arrays must be of the same length")
ValueError: All arrays must be of the same length

Since I am not able to attach any file other than an image file Here is the code

import pandas as pd
import plotly.express as px

data = pd.read_csv("combined.csv")

years = ['2021 payable 2022', '2022 payable 2023', '2023 payable 2024']
neighborhoodIds = list(set(data['neighborhoodId']))

fig_dict = {
    "data": [],
    "layout": {},
    "frames": []
}

fig_dict["layout"]["xaxis"] = {"title": "Longitude"}
fig_dict["layout"]["yaxis"] = {"title": "Latitude"}
fig_dict["layout"]["zaxis"] = {"title": "Total Value"}
fig_dict["layout"]["hovermode"] = "closest"

fig_dict["layout"]["updatemenus"] = [
    {
        "buttons": [
            {
                "args": [
                    None,
                    {
                        "frame": {"duration": 500, "redraw": False},
                        "fromcurrent": True,
                        "transition": {"duration": 300, "easing": "quadratic-in-out"}
                    }
                ],
                "label": "Play",
                "method": "animate"
            },
            {
                "args": [
                    [None],
                    {
                        "frame": {"duration": 0, "redraw": False},
                        "mode": "immediate",
                        "transition": {"duration": 0}
                    }
                ],
                "label": "Pause",
                "method": "animate"
            }
        ],
        "direction": "left",
        "pad": {"r": 10, "t": 87},
        "showactive": False,
        "type": "buttons",
        "x": 0.1,
        "xanchor": "right",
        "y": 0,
        "yanchor": "top"
    }
]

sliders_dict = {
    "active": 0,
    "yanchor": "top",
    "xanchor": "left",
    "currentvalue": {
        "font": {"size": 20},
        "prefix": "Year:",
        "visible": True,
        "xanchor": "right"
    },
    "transition": {"duration": 300, "easing": "cubic-in-out"},
    "pad": {"b": 10, "t": 50},
    "len": 0.9,
    "x": 0.1,
    "y": 0,
    "steps": []
}

for meighborhoodId in neighborhoodIds:
    dataset_by_year = data[data["year"] == years[0]]
    dataset_by_year_and_neighborhoodId = dataset_by_year[dataset_by_year["neighborhoodId"] == meighborhoodId]

    data_dict = {
        "x": list(dataset_by_year_and_neighborhoodId["longitude"]),
        "y": list(dataset_by_year_and_neighborhoodId["latitude"]),
        "z": list(dataset_by_year_and_neighborhoodId["totalActual"]),
        "mode": "markers",
        "text": list(dataset_by_year_and_neighborhoodId["uniquePropertyId"]),
        "marker": {
            "sizemode": "area",
            "sizeref": 200000,
            "size": list(dataset_by_year_and_neighborhoodId["landAcres"])
        },
        "name": meighborhoodId
    }
    fig_dict["data"].append(data_dict)


# make frames

for year in years:
    frame = {"data": [], "name": year}

    for neighborhoodId in neighborhoodIds:
        dataset_by_year = data[data["year"] == year]
        dataset_by_year_and_neighborhoodId = dataset_by_year[dataset_by_year["neighborhoodId"] == neighborhoodId]

        data_dict = {
            "x": list(dataset_by_year_and_neighborhoodId["longitude"]),
            "y": list(dataset_by_year_and_neighborhoodId["latitude"]),
            "z": list(dataset_by_year_and_neighborhoodId["totalActual"]),
            "mode": "markers",
            "text": list(dataset_by_year_and_neighborhoodId["uniquePropertyId"]),
            "marker": {
                "sizemode": "area",
                "sizeref": 200000,
                "size": list(dataset_by_year_and_neighborhoodId["landAcres"])
            },
            "name": neighborhoodId
        }
        frame["data"].append(data_dict)

    fig_dict["frames"].append(frame)

    slider_step = {
        "args": [
            [year],
            {
                "frame": {"duration": 300, "redraw": False},
                "mode": "immediate",
                "transition": {"duration": 300}
            }
        ],
        "label": year,
        "method": "animate"
    }
    sliders_dict["steps"].append(slider_step)


fig_dict["layout"]["sliders"] = [sliders_dict]


fig = px.scatter_3d(
    fig_dict
)

fig.show()

and here are the top few lines of the data. the data is written to a file named β€œcombined.csv” The file contains 550,752 records (lines of data) in it .

uniquePropertyId,neighborhoodId,marketAreaId,subdivisionId,latitude,longitude,year,totalActual,totalAssessed,landAcres
27273,7024,10,83000,39.8696,-105.282,2021 payable 2022,908786.0,64978.0,5.194
53261,3005,8,98400,39.7339,-105.143,2021 payable 2022,465075.0,33253.0,0.2297
67813,3006,8,539200,39.7262,-105.15,2021 payable 2022,406818.0,29088.0,0.2316
176772,3005,8,834800,39.7371,-105.151,2021 payable 2022,533279.0,38129.0,0.6887
27273,7024,10,83000,39.8696,-105.282,2022 payable 2023,908786.0,63160.0,5.194
53261,3005,8,98400,39.7339,-105.143,2022 payable 2023,465075.0,32323.0,0.2297
67813,3006,8,539200,39.7262,-105.15,2022 payable 2023,406818.0,28274.0,0.2316
176772,3005,8,834800,39.7371,-105.151,2022 payable 2023,533279.0,37063.0,0.6887
27273,7024,10,83000,39.8696,-105.282,2023 payable 2024,1468034.0,99313.0,5.194
53261,3005,8,98400,39.7339,-105.143,2023 payable 2024,589250.0,39863.0,0.2297
67813,3006,8,539200,39.7262,-105.15,2023 payable 2024,527536.0,35688.0,0.2316
176772,3005,8,834800,39.7371,-105.151,2023 payable 2024,764236.0,51701.0,0.6887

any help would be greatly appreciated

Hey kgschloser. This looks to be a Pandas error where your data is off different lengths.

This error occurs when you attempt to create a pandas DataFrame and not every column in the DataFrame has the same length

The following link should help you with your data .

1 Like