I have survey data in the dataframe. I can use print(list(survey_data.columns.values)) to get headers which are (not listing all 27 columns here but here is a sample)
['Age', 'Gender', 'Country', 'family_history']
I can use the following to get unique values of each column in for loop as follows:
for col in survey_data:
print(survey_data[col].unique())
[37 44 32 31 33 35 39 42 23 29 36 27 46 41 34 30 40 38 50 24 28 26 22 19 25 45 21 43 56 60 54 55 48 20 57 58 47 62 51 49 53 61]
I want to print column headers and unique values as follows
Desired output:
Age = [37 44 32 31 33 35 39 42 23 29 36 27 46 41 34 30 40 38 50 24 28 26 22 19 25 45 21 43 56 60 54 55 48 20 57 58 47 62 51 49 53 61]
Gender = ['F' 'M' 'T']
Country = ['United States' 'Canada' 'United Kingdom' 'Bulgaria' 'France' 'Portugal' 'Switzerland' 'Poland' 'Australia' 'Germany' 'Mexico' 'Brazil' 'Slovenia' 'Costa Rica' 'Austria' 'Ireland' 'India' 'South Africa' 'Russia' 'Italy' 'Netherlands' 'Sweden' 'Colombia' 'Latvia' 'Romania' 'Belgium' 'New Zealand' 'Spain' 'Finland' 'Uruguay' 'Israel' 'Bosnia and Herzegovina' 'Hungary' 'Singapore' 'Japan' 'Nigeria' 'Croatia' 'Norway' 'Thailand' 'Denmark' 'Greece' 'Moldova' 'Georgia' 'China' 'Czech Republic' 'Philippines']
I thought a statement would get me there.
print(list(survey_data.columns.values) for col in survey_data[col].unique())
Instead I get <generator object at 0x0000031EF53F3C80>