4

I'm panda library in python getting error

"None of [Index(['Dokuman', 'Sinif'], dtype='object')] are in the [columns]"

classes = ['ekonomi', 'spor', 'teknoloji', 'teknoloji', 'saglik', 'saglik', 'spor', 'ekonomi']

df_docs = pd.DataFrame.from_dict({'Dokuman': docs, 'Sinif': classes}, orient='index')


df_docs = df_docs[['Dokuman', 'Sinif']] #throws the error here
mustafaerdogmus
  • 111
  • 1
  • 2
  • 9
  • Don't use `orient='index'` if you don't want your data oriented along the index (use `'columns'`) – cs95 Apr 06 '19 at 19:56
  • Or better still, just `df_docs = pd.DataFrame({...})` is enough – cs95 Apr 06 '19 at 19:57
  • i changed the code df_docs = pd.DataFrame.from_dict({'Dokuman': docs, 'Sinif': classes}) "arrays must all be same length" I got the error – mustafaerdogmus Apr 06 '19 at 19:58
  • i changed the code df_docs = pd.DataFrame({'Dokuman': docs, 'Sinif': classes}) ı got the error "arrays must all be same length" – mustafaerdogmus Apr 06 '19 at 20:03
  • How there is no other method ? – mustafaerdogmus Apr 07 '19 at 15:04
  • This may be useful: https://stackoverflow.com/questions/20638006/convert-list-of-dictionaries-to-a-pandas-dataframe/53831756#53831756 there's information on loading a DataFrame if the length of the lists are not equal. – cs95 Apr 07 '19 at 16:54
  • thanks @coldspeed just like you said. the number of records in the docs is not equal to the number of records in the classes, so I am getting the error – mustafaerdogmus Apr 07 '19 at 17:33

1 Answers1

0

the number of records in the docs is not equal to the number of records in the classes, so I am getting the error

mustafaerdogmus
  • 111
  • 1
  • 2
  • 9