0
$\begingroup$

I am trying to make a submission of a machine learning classification problem. I have a test dataset where to try my model. To submit I have to build a csv file. The prblem is that when I go building this csv file by doing:

sub = pd.DataFrame({'instructions': test['instructions'],'compiler':new_pred_class}).to_csv('sub.csv')
sub.head()

I get the following error message:

AttributeError                            Traceback (most recent call last)
<ipython-input-37-f223adaf5068> in <module>
  1 sub = pd.DataFrame({'instructions': test['instructions'],'compiler':new_pred_class}).to_csv('sub.csv')
----> 2 sub.head()

AttributeError: 'NoneType' object has no attribute 'head'

Can somebody please help me? Thank's in advance.

$\endgroup$
1
$\begingroup$

The return type of pandas.DataFrame.to_csv is None.

So your first line assigns sub = None:

sub = pd.DataFrame({'instructions': test['instructions'],'compiler':new_pred_class}).to_csv('sub.csv')

This is probably what you wanted:

sub = pd.DataFrame({'instructions': test['instructions'],'compiler':new_pred_class})
sub.to_csv('sub.csv')
sub.head()
|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.