A为一个index对象,B为一个可迭代对象,返回B中每个item在A这个index列表里的索引坐标
**DataFrame.corr
(method='pearson', min_periods=1)[source]**Compute pairwise correlation of columns, excluding NA/null values.Parametersmethod{‘pearson’, ‘kendall’, ‘spearman’} or callableMethod of correlation:
• pearson : standard correlation coefficient
• kendall : Kendall Tau correlation coefficient
• spearman : Spearman rank correlation
• callable: callable with input two 1d ndarraysand returning a float. Note that the returned matrix from corr will have 1
Python3 pandas库 (27) 多列拼接成一列.str.cat() - 知乎 (zhihu.com)
df_res['datetime_booked']=pd.to_datetime(df_res['datetime_booked'],format="%m/%d/%y %H:%M")
python中时间日期格式化符号:
先用map获取符合指定条件的bool列表,(这里给map的函数需要返回bool)再根据bool索引取dataframe的对应子frame,再取子frame的index传给drop
time_list='17:30, 17:45, 18:00, 18:15, 20:45, 21:00, 21:15, 21:30'.split(", ")
df_res=df_res[df_res['reservation_datetime'].map(lambda x:x.ctime().split()[3][:5] in time_list)]
# 或者直接用drop
df_res.drop(index=df_res[df_res['reservation_datetime'].map(lambda x:x.ctime().split()[3][:5] in time_list)].index[0])
unstack函数 level里传入要分类的属性
得到的DataFrame的列名是Multiindex