question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pairplot seems to miss interpret strings such as '0' and '1' as integers

See original GitHub issue

After casting a panda column from integers to string, pairplot keeps interpreting this column as containing numerical values it seems.

I am currently using: panda: 0.21.1 numpy: 1.13.3 sns 0.8.1 matplotlib version: 2.1.1 matplotlib backend: module://ipykernel.pylab.backend_inline system: sys.version_info(major=2, minor=7, micro=12, releaselevel='final', serial=0)

Example, generate some data: test = pd.DataFrame(np.random.randn(10, 4), columns=['A', 'B', 'C', 'D']) Threshold the first column test['A'] = test['A'].apply(lambda x: 0 if x < 0 else 1)

and cast:

test['A'] = test['A'].astype(str)

Alternatively, this also produces the same error later:

test['A'] = test['A'].apply(str)

Calling pairplot, with the A column _ = sns.pairplot(test, hue="A") results in ValueError: setting an array element with a sequence

Defining and applying a map solves this issue: custom_map = {'0': 'zero', '1': 'one'}

test['A'] = test['A'].map(custom_map)

Full example in a jupyter notebook:

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
mwaskomcommented, Dec 13, 2017

And in the meantime you should do

sns.pairplot(test, hue="A", vars=["B", "C", "D"])
2reactions
MaozGelbartcommented, Sep 3, 2019

With matplotlib 3.1.0 and seaborn 0.9.0, I get the sample code by @mdiephuis to run and plot without any errors. Also for the example by @mwaskom for ax.hist inconsistencies.

Read more comments on GitHub >

github_iconTop Results From Across the Web

seaborn pairplot after converting a integer column to string
I have a dataframe and in one case I have to convert one of the column to string; After converting to String. Pairplot()...
Read more >
Creating Pair Plots in Seaborn with sns pairplot - Datagy
In this tutorial, you'll learn how to create pair plots in Seaborn, using the sns. pairplot() function. These visualizations plot pairwise ...
Read more >
Introduction to Data Visualization in Python - Trenton McKinney
The coordinates and lengths are values between 0 and 1 representing lengths relative to the dimensions of the figure. After issuing a plt.axes()...
Read more >
Chapter 4. Visualization with Matplotlib - O'Reilly
In [ 1 ]: import matplotlib as mpl import matplotlib.pyplot as plt ... While most plt functions translate directly to ax methods (such...
Read more >
4 Types of Classification Tasks in Machine Learning
Binary classification refers to predicting one of two classes and ... a unique integer is assigned to each class label, e.g. “spam” =...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found