-1

Old code reads HTML and output it to CSV

I have an old python 3 code:

self.df, = pandas.read_html(my_html_file)
self.df.to_csv(my_csv_file, index=False)

without comma in first line pandas returns a list, with the comma DF object that can be send to CSV file in second line. I do not understand that comma in the first line

1 Answers1

2

I think it convert one element list to scalar by one element tuple, because read_html return list of DataFrames - in your code one DataFrame list.

Sample:

a = [1]
b, = a
#() are optional
#(b,) = a
print (b)
1

More readable is select first list by indexing - [0]:

self.df = pandas.read_html(my_html_file)[0]
self.df.to_csv(my_csv_file, index=False)
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252