0
     I have a datframe,df

                2.3.6     16.3.9   9.2.7  43.5.2   4.5.6   45.2.1
August            2         1       8       3        10      3
September         7         0       7       3        5       4
October           1         2       5       3        2       2
November          0         0       8       9        0       3

I want a new dataframe to just keep the first 2 columns

I used the following code:

df2=df.loc[:, df['16.3.9']]
print (df2)

KeyError: 'None of [ \nSeptember 2.0\nOctober 2.0\nNovember 0.0\nName: 16.3.9, dtype: float64] are in the [columns]'

Or perhaps is there a way I can slice the dataframe,df into 1 figure with different subplots that have 2 columns each?

Bode
  • 527
  • 2
  • 9
  • 19
  • after trying your code, I got this: TypeError: cannot do slice indexing on with these indexers [2] of – Bode Jan 13 '18 at 15:15
  • You are mixing different indexing methods here. Either use `df.iloc[:,:2]` or `df.loc[:,["2.3.6","16.3.9"]]` or `df[["2.3.6","16.3.9"]]` to select the first two columns. – ImportanceOfBeingErnest Jan 13 '18 at 15:21
  • thanks @ImportanceOfBeingErnest Is there a way I can slice the dataframe,df into 1 figure with different subplots that have 2 columns each? – Bode Jan 13 '18 at 15:29
  • Yes, but that question has also already been asked somewhere. Please look for respecive SO question first. – ImportanceOfBeingErnest Jan 13 '18 at 15:30

0 Answers0