尝试从熊猫数据框中绘制数据

时间:2021-03-16 15:41:35

标签: python pandas altair

我正在尝试使用 Pandas 数据框构建一个简单的折线图。数据框包含一个带有日期条目的列。每个日期有几行数据。我想按日期对数据进行分组,计算每组的条目并使用 altair 折线图显示数据。

我尝试了几种方法,但找不到解决方案。我认为将数据复制到新的数据帧将是最好的解决方案。 通过以下函数从 csv 填充数据框

def read_csv(rows):
    parse_dates = ['Gemeldet_Am']
    data = pd.read_csv(path+file,nrows=rows, parse_dates=parse_dates)
    data['Gemeldet_Am'] = pd.to_datetime(data['Gemeldet_Am']).dt.date
    return data

数据帧的打印看起来像这样:

enter image description here

我想按蓝色框中的所有内容分组,然后计算红色框中的数据。然后 Altair 图表应该显示每天(蓝色数据)红色数据的总和

1 个答案:

答案 0 :(得分:0)

以下是一个折线图示例,其中包含按日期分组的计数以及与您的数据相似的数据:

Node* createNode(void* item){
        Node *new_node;

    if ((new_node = malloc(sizeof(Node))) == NULL)
        return NULL;

    new_node->item = item;
    new_node->nodes[0] = NULL;
    new_node->nodes[1] = NULL;

    return new_node;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Initializes the fields on the BST. Returns nothing.
void initBinaryTree(BST* tree, int item_size){
Node* root = NULL;
root = (Node *)malloc(sizeof(Node));
Node* left = NULL;
root = (Node *)malloc(sizeof(Node));
Node* right = NULL;
root = (Node *)malloc(sizeof(Node));

tree->tree_root = root;
tree->tree_root->nodes[0] = left;
tree->tree_root->nodes[1] = right;
tree->item_size = item_size;
tree->depth = 0;

}

enter image description here