Unable to build data map using twine

I was able to use pandas groupbyto create a new one DataFrame, but I get an error message when creating barplot. Groupby team:

invYr = invoices.groupby(['FinYear']).sum()[['Amount']]

Which creates a new DataFrameone that looks correct to me.

New DataFrameinvYr

Duration:

sns.barplot(x='FinYear', y='Amount', data=invYr)

I get an error message:

ValueError: Could not interperet input 'FinYear'

It seems that the problem is related to the index, being FinYear, but unfortunately I could not solve the problem even when using reindex.

+4
source share
1 answer
import pandas as pd
import seaborn as sns

invoices = pd.DataFrame({'FinYear': [2015, 2015, 2014], 'Amount': [10, 10, 15]})
invYr = invoices.groupby(['FinYear']).sum()[['Amount']]

>>> invYr
         Amount
FinYear        
2014         15
2015         20

, , , invYr invoices FinYear . :

1) . . data, Seaborn , / "FinYear" "Amount", . , , y=invYr.Amount, dataframe/series, , . - .

sns.barplot(x=invYr.index, y=invYr.Amount)

2) , . , reset, .

sns.barplot(x='FinYear', y='Amount', data=invYr.reset_index())

3) - as_index=False, groupby, .

invYr = invoices.groupby('FinYear', as_index=False).Amount.sum()
sns.barplot(x='FinYear', y='Amount', data=invYr)

.

enter image description here

+8

Source: https://habr.com/ru/post/1627093/


All Articles