이승훈
이승훈

Reputation: 360

pandas dataframe subplot grouping by columns

df = pd.DataFrame([[0, 1, 2], [0, 1, 2]])
df.plot(subplots=True)

I want subplot by group [0, 1] and [2] columns. is there the way?

Upvotes: 1

Views: 44

Answers (1)

jezrael
jezrael

Reputation: 862691

You can use DataFrameGroupBy.plot by Index.map by dictionary for 2 groups:

mapping = {0:'a', 1:'a', 2:'b'}

df.groupby(df.columns.map(mapping.get), axis=1).plot()

Detail:

print (df.columns.map(mapping.get))
Index(['a', 'a', 'b'], dtype='object')

Upvotes: 1

Related Questions