pairplot seems to miss interpret strings such as '0' and '1' as integers
See original GitHub issueAfter 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:
- Created 6 years ago
- Comments:13 (6 by maintainers)
Top GitHub Comments
And in the meantime you should do
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.