panda quantile, group by, summary row to list
作者:互联网
import pandas as pd
import numpy as np
function to get summary list names
def deleteDuplicatelist(listA):
#return list(set(listA))
return sorted(set(listA), key = listA.index)
FCData=pd.read_csv(r’/Users/samwang/Downloads/BYD FC-Export-ID-115213015836970-2021-09-14T00_00_00-2021-09-27T23_59_59-X5476-DEVELOPMENT5-Versions-2.csv’)
print(FCData[‘Max Load’].head())
print(FCData[[‘Max Extension’,“Max Load.1”]].describe())
print(FCData.columns)
print(FCData.head())
print(FCData[[‘Site’,‘Product’]])
FCSdata= FCData[[‘Site’,‘Product’,‘SerialNumber’,‘StartTime’,‘test_type’,‘Max Load’]]
print(FCSdata.describe())
set startime as time format , then change to year-month-day format.
FCData[‘dateFormat’]=pd.to_datetime(FCData[“StartTime”],format="%Y/%m/%d")
FCData[‘day’]=FCData[‘dateFormat’].dt.strftime(’%Y-%m-%d’)
print(FCData)
LG and Sm by SN
product =[]
for a in FCData[‘SerialNumber’]:
if “13H9” in a:
product.append(“SM”)
elif “13HC” in a:
product.append(“LG”)
else:
“abnormalSn”
FCData[“product”]=product
list1= (deleteDuplicatelist(product))
print(list1)
quantileFrame=FCData[‘Max Load.1’].groupby(by=(FCData[“product”])).quantile(q=[0.05, 0.1, 0.63])
quantileFrame=FCData.groupby(by=(FCData[“product”]))[‘Max Load.1’].agg([‘mean’,“max”,“quantile”])
quantileFrame=FCData.groupby(by=[“product”,‘test_type’,“day”])[‘Max Load.1’].agg([‘mean’,“min”,“quantile”,np.percentile(q=95)])
quantileFrame=FCData.groupby(by=[“product”,‘test_type’,“day”])[‘Max Load.1’].agg([np.min,np.mean,‘count’,lambda x: x.quantile(0.05),lambda x: x.quantile(0.1)])
quantileFrame=FCData.groupby(by=[“product”,‘test_type’,“day”])[‘Max Load.1’].quantile(q=[0.05, 0.1, 0.63])
print(quantileFrame)
FCTable = FCData.pivot_table(index=[‘test_type’,“day”],values=‘Max Load.1’,aggfunc=“mean”)
print(FCTable)
‘Station ID’,‘Test Pass/Fail Status’,‘EndTime’‘fixture_id’‘Max extension’ ,‘Max Extension’, ‘Max Load’
print(FCData[FCData[‘test_type’].str.contains(‘CCP_Bare’)][“Max Load.1”].quantile(q=[0.05,0.1,0.63]))
print(FCData.groupby(by=“test_type”)[‘Max Load.1’].agg(“quantile(0.3)”))
list_name =(FCData[‘test_type’].values.tolist())
list_name=deleteDuplicatelist(list_name)
day_list = FCData[‘day’].values.tolist()
day_list=deleteDuplicatelist(day_list)
print(list_name)
print((day_list))
for day in day_list:
for name in list_name:
# print(name, FCData[FCData['test_type'].str.contains(name)]["Max Load.1"].quantile(q=[0.05, 0.1, 0.63]).values,sep=" ")
dateoutput=FCData[(FCData['test_type'].str.contains(name)) & (FCData['day'].str.contains(day))]["Max Load.1"]
# print(name, day, dateoutput.min(), dateoutput.quantile(q=[0.05, 0.1, 0.63]).values,sep=" ")
标签:group,Max,quantile,list,FCData,print,day 来源: https://blog.csdn.net/qq_38844711/article/details/120613375