[英]How do i write a custom function to show value counts of each variable in a dataframe along with levels?
I have written some of code for the below but unable to get write code to display value counts for each levels我已经为下面的代码编写了一些代码,但无法编写代码来显示每个级别的值计数
def info(data):
return pd.DataFrame({"Data Type":data.dtypes,
"No of Levels":data.apply(lambda x: x.nunique(),axis=0)})
Output输出
Data Type No of Levels Levels
A int64 3 [1 2 3]
B int64 8 [1 2 3 4 5 6 7 8]
C int64 6 [1 2 3 4 5 6]
D object 4 ['Apple' 'Mango' 'Grapes' 'Orange']
E object 3 ['Cauliflower' 'Potato' 'Tomato']
F int64 2 [0 1]
G int64 2 [1 0]
H int64 2 [1 0]
Desired Output期望输出
Data Type No of Levels Value Counts Levels
A int64 3 1:100; 2:150; 3:200 [1 2 3]
B int64 8 0: 100; 1:200; 3:300... [1 2 3 4 5 6 7 8]
C int64 6 0: 100; 1:200; 3:300... [1 2 3 4 5 6]
D object 4 Apple:5,Mango:150... ['Apple' 'Mango' 'Grapes' 'Orange']
E object 3 Cauliflower:5,Potato:150...['Cauliflower' 'Potato' 'Tomato']
F int64 2 0: 100; 1:200 [0 1]
G int64 2 0: 100; 1:200 [1 0]
H int64 2 0: 100; 1:200 [1 0]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.