I have a quick question regarding data frames. Say I have a dataframe that outputs:
City Color State
0 Dallas Red TX
1 Seattle Blue WA
2 Boston Purple MA
3 Concord Yellow NH
How do I loop through the rows of the dataframe so that I can get this output?
'Dallas', 'Red', 'TX'
'Seattle', 'Blue', 'WA'
'Boston', 'Purple', 'MA'
'Concord', 'Yellow', 'NH'
Similarly, if I have a dataframe that just contains one column such as:
City
0 Dallas
1 Seattle
2 Boston
3 Concord
Is there a way to just output this?
'Dallas'
'Seattle'
'Boston'
'Concord'
My original code was looping through the dataframe using df.values, and then adding the "'" character at the beginning and end while stripping the bracket character. However, this obviously only works for just one column, and I would rather the code work if I continued to have N amount of columns.
Any help is greatly appreciated!
for index, row in df.iterrows(): print("'{}', '{}', '{}'".format(row.City, row.Color, row.State))orfor index, row in df.iterrows(): print(f"'{row.City}', '{row.Color}', '{row.State}'")