AttributeError: module 'pandas' has no attribute 'to_csv'
to_csv
is a method of a DataFrame
object, not of the pandas
module.
df = pd.DataFrame(CV_data.take(5), columns=CV_data.columns)# whatever manipulations on dfdf.to_csv(...)
You also have a line pd.DataFrame(CV_data.take(5), columns=CV_data.columns)
in your code.
This line creates a dataframe and then discards it. Even if you were successfully calling to_csv
, none of your changes to CV_data
would have been reflected in that dataframe (and therefore in the outputed csv file).
This will do the job!
#Create a DataFrame: new_df = pd.DataFrame({'id': [1,2,3,4,5], 'LETTERS': ['A','B','C','D','E'], 'letters': ['a','b','c','d','e']})#Save it as csv in your folder: new_df.to_csv('C:\\Users\\You\\Desktop\\new_df.csv')
Solution-You should write df.to_csv instead of pd.to_csv
Justification-to_csv is a method to an object which is a df (DataFrame); while pd is Panda module.
Hence, your code was not working and throwing this Error "AttributeError: module 'pandas' has no attribute 'to_csv'"