0
点赞
收藏
分享

微信扫一扫

pandas 根据"_"分割列

dict_column_测量Or料温 = {
    "_".join([str(key), str(value_2)]): value_2
    for key, value_1 in dict_df.items() 
    for value_2 in value_1.columns
    if (('测量' in str(value_2)) or ('料温' in str(value_2)))
}
df_column_测量Or料温 = pd.DataFrame.from_dict(dict_column_测量And料温, orient='index').reset_index()
df_column_测量Or料温_concat = pd.concat([
    df_column_测量Or料温, 
    df_column_测量Or料温['index'].astype(str).str.split("_", expand=True)
], axis=1)
df_column_测量Or料温_concat.columns = ['key', 'value_2', 'key_', '_value_2']
df_column_测量Or料温_concat.pivot_table(
    index=['key_'],
    columns=['_value_2'],
    aggfunc=len,
    values=None
).T

举报

相关推荐

0 条评论