Reputation: 63
I have this code
import numpy as np
import pandas as pd
import csv
odata = pd.read_csv('email.csv')
data = odata.drop('content', axis=1, inplace=True)
data.to_csv('email-out.csv', index=False, sep=',')
And I got error like that:
Traceback (most recent call last):
File "cut.py", line 7, in <module>
data.to_csv('email-out.csv', index=False, sep=',')
AttributeError: 'NoneType' object has no attribute 'to_csv'
Where am I wrong? help me..please
Upvotes: 5
Views: 20678
Reputation: 14791
Change this line:
data = odata.drop('content', axis=1, inplace=True)
to this:
data = odata.drop('content', axis=1)
The inplace
flag causes the operation to happen in-place and return None
, instead of creating a new dataframe.
If you really do want the drop to happen in place, the alternative is to replace your code with something like the following:
odata = pd.read_csv('email.csv')
odata.drop('content', axis=1, inplace=True)
odata.to_csv('email-out.csv', index=False, sep=',')
Please refer to the documentation for more info.
Upvotes: 7