Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ch. 10 (clustering) bug #317

Open
darribas opened this issue Dec 10, 2023 · 1 comment
Open

Ch. 10 (clustering) bug #317

darribas opened this issue Dec 10, 2023 · 1 comment
Labels
keepup Changes to keep up with the evolution of the python stack

Comments

@darribas
Copy link
Member

Cell 40 (last one of code):

ami_scores = []
# for each cluster solution
for i_cluster_type in ("k5cls", "ward5", "ward5wq", "ward5wknn"):
    # for every other clustering
    for j_cluster_type in ("k5cls", "ward5", "ward5wq", "ward5wknn"):
        # compute the adjusted mutual info between the two
        ami_score = metrics.adjusted_mutual_info_score(
            db[i_cluster_type], db[j_cluster_type]
        )
        # and save the pair of cluster types with the score
        ami_scores.append((i_cluster_type, j_cluster_type, ami_score))
# arrange the results into a dataframe
results = pandas.DataFrame(
    ami_scores, columns=["source", "target", "similarity"]
)
# and spread the dataframe out into a square
results.pivot("source", "target", "similarity")

Currently returns (with pandas 2.1.1) the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[40], line 17
     13 results = pandas.DataFrame(
     14     ami_scores, columns=["source", "target", "similarity"]
     15 )
     16 # and spread the dataframe out into a square
---> 17 results.pivot("source", "target", "similarity")

TypeError: pivot() takes 1 positional argument but 4 were given
@darribas darribas added the keepup Changes to keep up with the evolution of the python stack label Dec 10, 2023
@dfolch
Copy link

dfolch commented Jan 4, 2024

The following update should be backwards compatible to earlier versions of Pandas since the parameter names have not changed.

Original

results.pivot("source", "target", "similarity")

Update

results.pivot(columns="source", index="target", values="similarity")

darribas added a commit to darribas/geographic-data-science that referenced this issue Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keepup Changes to keep up with the evolution of the python stack
Projects
None yet
Development

No branches or pull requests

2 participants