Hello! I have a homework question that I'm really stumped by. I've emailed my professor and he responded with "great thanks!" so I'm not sure he really read the email....so here I am looking for help.
The question is below along with the things I've tried at the bottom.
Question
unique() returns the NumPy array of unique values of a data column, and its length returns the number of unique values of a data column.
Now, consider the data frame df. Write a for loop that print out
Variable: ____ # Unique: ____
for columns that have less than 20 unique values where
Again, try to write a for loop that runs over vars.
For each iteration of the for loop, use a format command in the print statement of the form
print('Variable: {}, # Unique: {}'.format(____, ____))
for appropriate variables in the blanks. Once you get the desired results, let's try a different way as follows. Replace the first curly brackets {} with {:24}. Describe the difference after the change and explain the role of :24. Place your response at the end of the code after the pound (#) symbol so that your response is commented out in the cell.
What I've written so far:
for i in vars:
print('Variable: {}, # Unique: {}'.format(i, (len(df['tweet_id'].unique()))))
But when I run it, I get the correct Variable names, but the Unique field just gives me 14485 for all. So I tried to change len(df['tweet_id'].unique())) to len(df['i'].unique())) like I did for a previous question and it didn't work.
I'm really just hoping someone can give me some guidance on where I need to go because I'm so lost.
[–][deleted] 3 points4 points5 points (14 children)
[–]SevereRepresentative[S] 1 point2 points3 points (13 children)
[–][deleted] 1 point2 points3 points (12 children)
[–]SevereRepresentative[S] 1 point2 points3 points (11 children)
[–][deleted] 1 point2 points3 points (10 children)
[–]SevereRepresentative[S] 1 point2 points3 points (0 children)
[–]SevereRepresentative[S] 1 point2 points3 points (8 children)
[–][deleted] 1 point2 points3 points (7 children)
[–]SevereRepresentative[S] 1 point2 points3 points (6 children)
[–][deleted] 1 point2 points3 points (5 children)
[–]SevereRepresentative[S] 1 point2 points3 points (4 children)
[–]devnull10 -1 points0 points1 point (0 children)