AttributeError: module 'pandas' has no attribute 'to_csv'

随声附和 提交于 2019-12-06 07:33:46

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 df

df.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')
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!