import pandas as pd
#Pandas zählen die Anzahl der Vorkommen von Elementen jedes Attributs.Gibt eine Liste von Serien zurück
def count_attibute_value(df):
list_of_attribute_series=[]
columns_list = df.columns.values
#attribute_num = len(columns_list)
for attribute in columns_list:
list_of_attribute_series.append(df[attribute].value_counts())
return list_of_attribute_series
if __name__ == '__main__':
#example
df = pd.DataFrame({"item":[c for _ in range(5) for c in ["apple", "banana","orange"]],"rank":[chr(i%7+65) for i in range(15)]})
l = count_attibute_value(df)
print(df)
print(l[0])
print(l[1])
Recommended Posts