Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i use Seaborn.lmplot function without naming DataFrame columns?

I want to use Seaborn.lmplot for scattering Dataframe's "column 1" vs "column 2" , but in according to Seaborn documentation :

Seaborn.lmplot(x, y, data, hue=None, ...)

We should provide names of columns for using this function, in other words Dataframes columns should be strings instead of integers.

I've tried a following methods, but none of them works!

import seaborn as sns
import pandas as pd
df = pd.read_csv('someData.csv',sep=',', header=None)

sns.lmplot(0,1, data= df)
sns.lmplot(df[0], df[1])
sns.lmplot("0","1",data= df)

and my dataFrame is something like: enter image description here

Is there any method that I can use Seaborn.lmplot without naming columns!

like image 865
daniel nasiri Avatar asked Aug 31 '17 07:08

daniel nasiri


People also ask

What does the function SNS Lmplot () perform in Seaborn library?

lmplot() method is used to draw a scatter plot onto a FacetGrid.

How do I select column names in a Dataframe?

Selecting columns based on their name This is the most basic way to select a single column from a dataframe, just put the string name of the column in brackets. Returns a pandas series. Passing a list in the brackets lets you select multiple columns at the same time.

What does a Lmplot show?

The lineplot (lmplot) is one of the most basic plots. It shows a line on a 2 dimensional plane. You can plot it with seaborn or matlotlib depending on your preference.


1 Answers

Seaborn does not allows for unnamed columns.
However, an easy solution is to rename the columns just for the purpose of plotting. Mapping the integer to a string (lambda x: str(x)) would allow to use strings as column names for the seaborn plot.

sns.lmplot(x="0", y="1", data=df.rename(columns=lambda x: str(x)))

The original dataframe will stay unchanged.

like image 170
ImportanceOfBeingErnest Avatar answered Oct 19 '22 07:10

ImportanceOfBeingErnest