Python Forum
Pandas to_csv in for loop AttributeError: 'tuple' object has no attribute 'to_csv'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pandas to_csv in for loop AttributeError: 'tuple' object has no attribute 'to_csv'
#1
Hi all,

Thank you in advance for all suggestions. I am attempting to read data from a csv file and populate a field ('Result_Header') with a value. The example below is just to help me understand the concept -- the final code will actually be populating a value from an api call (that part I figured out). I am just getting tripped up on the to_csv function.

print(data) shows me that the column is being populated correctly, it is just the to_csv where I get the error below.

import pandas as pd

data = pd.read_csv("C:\\Users\\X\\Documents\\X\\some_data.csv")

for data in data.iterrows():

    #desired_number = data[1][5]
    desired_number = data[1]['Number_Header']
    data[1]['Result_Header'] = desired_number
    data[1]['Result_Notes'] = 'This is your desired number'

    print(data) 


data.to_csv("C:\\Users\\X\\Documents\\X\\some_data_output.csv")
Error:
AttributeError: 'tuple' object has no attribute 'to_csv'
Reply


Messages In This Thread
Pandas to_csv in for loop AttributeError: 'tuple' object has no attribute 'to_csv' - by NSearch - Apr-22-2019, 01:43 PM
RE: Pandas to_csv in for loop - by Yoriz - Apr-22-2019, 02:30 PM
RE: Pandas to_csv in for loop - by NSearch - Apr-22-2019, 02:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  error "list object has no attribute transpose()" usercat123 4 4,457 Jan-28-2022, 12:01 PM
Last Post: usercat123
  Python PDF merging from an excel pandas for loop siraero 0 2,266 Aug-16-2020, 09:34 AM
Last Post: siraero
  What is the mechanism of numpy function returning pandas object? Ibaraki 2 2,635 Apr-04-2020, 10:57 PM
Last Post: Ibaraki
  Python Pandas for loop/while loop question mrashy 1 3,978 Mar-24-2020, 04:39 AM
Last Post: deanhystad
  AttributeError: (“module 'pandas' has no attribute 'rolling_std'” Mariana136 4 7,745 Sep-23-2019, 12:56 PM
Last Post: Mariana136
  Loop pandas data frame by position ? Johnse 1 2,345 Sep-06-2019, 12:26 AM
Last Post: scidam
  AttributeError: module 'numpy' has no attribute 'array aapurdel 7 46,466 May-29-2019, 02:48 AM
Last Post: heiner55
  AttributeError: 'NoneType' object has no attribute 'all' synthex 2 5,412 Mar-07-2019, 11:11 AM
Last Post: synthex
  Please help with AttributeError: 'Netz' object has no attribute 'conv' DerBerliner 2 3,899 Feb-27-2019, 06:01 PM
Last Post: DerBerliner
  'list' object has no attribute 'reshape' SamSoftwareLtd 1 15,820 Nov-04-2018, 10:38 PM
Last Post: stullis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020