1

I have a data set I am transposing with a loop that looks like this.

 x = []
 for index, row in s1.iterrows():
      x = row 
      tt = pd.DataFrame(x)

I am then using the pandas data frame to html function to send an email for each row of the s1 data frame transposed. My issue is that when I convert the series to a data frame at the end of the loop it includes the index for each iteration of the loop when it prints. So the output looks like this.

            0
 s1.Col1    s1.val1
 s1.Col2    s1.val2
 s1.Col3    s1.val3
 s1.Col4    s1.val4
 s1.Col5    s1.val5
 s1.Col6    s1.val6


            1
 s1.Col1    s1.val1
 s1.Col2    s1.val2
 s1.Col3    s1.val3
 s1.Col4    s1.val4
 s1.Col5    s1.val5
 s1.Col6    s1.val6

(Sorry I couldn't figure out how to put in a table)

So each email has all of the columns in the format I need but an index value of 0,1,2,3,4,5 etc. which I guess is being included as a column name. All I need to do is exclude the index value that is being output.

I am using the below code to generate the html for the email. So the object needs to be a data frame for this to work.

     email = "  {tt} "
     email = email.format(tt=tt.to_html())

Maybe there is an easier way to this. I am basically just trying to transpose the original data set and send an email with the table for each row. Any help would be appreciated. Thanks.

4
  • 1
    it is not very clear what you actually want to achieve, specially since you don't include the code that generates the html table. Can you update? also include the code that generates the print Commented Dec 28, 2018 at 17:36
  • I updated it. I am really just trying to transpose the original data set and send an email with the data and values for each row. I am using the to_html function so the output of the loop would need to be a data frame for that part to work. Maybe there is a better way to do this. Commented Dec 28, 2018 at 18:17
  • btw, you can transpose by doing s1 = s1.T Commented Dec 28, 2018 at 18:23
  • check this solution. maybe it helps stackoverflow.com/questions/40546119/… Commented Dec 28, 2018 at 18:23

1 Answer 1

1

I think there's an easy way, as .to_html() actually has a header flag. Check this out tt.to_html(header=False)?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.