I need help using pandas to group data. The data looks something like this:
12233: 5
12332: 5
12322: 5
12311: 4
22211: 4
12212: 3
Instead of it showing the 3 different numbers appearing 5 times, I would like it to just write how many unique numbers appear 5 times if that makes sense. So for this example, it would write that 3 unique numbers appeared 5 times and 2 unique numbers appeared 4 times. Any help would be appreciated.
How I would like the data to look:
5 : 3
4: 2
3: 1
Here is the code I currently have:
from collections import Counter
import time
import pandas as pd
filename = input("Enter name to save this file as:\n\n")
print("Your file will be saved as: " + filename + ".csv\n\n")
time.sleep(0.5)
print("Please copy/paste numbers into here.")
contents = []
def amount():
while True:
try:
line = input()
except EOFError:
break
contents.append(line)
return
amount()
count = Counter(contents)
print(count)
d = count
df = pd.DataFrame.from_dict(d, orient='index').reset_index()
df.columns = ['column1', 'column2']
df = df.sort_values(by=['column2'], ascending=False)
print(df)
df.to_csv(filename + ".csv", encoding='utf-8', index=False)