简体   繁体   English

pandas.DataFrame.to_csv问题(“ tuple”对象没有属性“ to_csv”)

[英]Issue with pandas.DataFrame.to_csv ('tuple' object has no attribute 'to_csv')

I have imported a csv file and manipulated the data with pandas. 我已经导入了一个csv文件,并使用了熊猫来处理数据。 I would now like to write out the df to a csv, but am receiving error: 'tuple' object has no attribute 'to_csv' 我现在想将df写出到csv,但收到错误:“ tuple”对象没有属性“ to_csv”

I have tried the following: 我尝试了以下方法:

   df = pd.read_csv(destintation_path + '/' + filename),
   index_col=False,
   usecols=[1,2,3], 
   parse_dates=[0],
   header=0,
   names=["lineItem_referenceNo", "lineItem_tenantId", "lineItem_intervalUsageStart"]
   logging.info(df)

   export_csv = df.to_csv(destintation_path + '/' + filename, header=True)

The returned message is: 返回的消息是:

'tuple' object has no attribute 'to_csv'

Any guidance appreciated. 任何指导表示赞赏。

Seems like you are closing you parenthesis too early. 似乎您太早关闭了括号。 Try this corrected line: 尝试以下更正的行:

df = pd.read_csv(destintation_path + '/' + filename,
   index_col=False,
   usecols=[1,2,3], 
   parse_dates=[0],
   header=0,
   names=["lineItem_referenceNo", "lineItem_tenantId", "lineItem_intervalUsageStart"])
logging.info(df)

I always use 我总是用

df.to_csv("filename.csv" )

and this works fine for me. 这对我来说很好。 It outputs the csv to the same directory of my notebook. 它将csv输出到我的笔记本的同一目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM