简体   繁体   English

从多个熊猫数据框列绘制图形

[英]Plotting a graph from multiple pandas data frame columns

I have a Pandas data frame with many columns (150), 140 out of them (the 10th column through out the 150th column) represent the weather degree values through time (through 140 days). 我有一个包含许多列(150)的Pandas数据框,其中有140列(第150列中的第10列)代表了一段时间(直到140天)的天气程度值。 Each column represents the degree for a different day. 每列代表不同日期的程度。 For two rows in my data frame (each row represents a different city), I want to plot a trend of all weather points, starting from the first (the 10th column), to the last (the 150th column). 对于数据框中的两行(每一行代表一个不同的城市),我想绘制所有天气点的趋势,从第一列(第10列)到最后一列(第150列)。

I can't manage to do it with the data frame as it is. 我无法按原样使用数据框来做到这一点。 Should I create a pivot table first? 我应该首先创建数据透视表吗? a list? 一个列表?

Do you have any idea how to approach it in an efficient way? 您是否知道如何以有效的方式进行处理?

Thank you 谢谢

If you want to select specified columns from your dataset, you can use filter function. 如果要从数据集中选择指定的列,则可以使用过滤器功能。 For example, let's create the new dataset: 例如,让我们创建新的数据集:

import pandas as pd

data = [
    ['a',2,3,4,5],
    ['b',2,3,4,5],
    ['c',2,3,4,5],
    ['d',2,3,4,5],
]

df = pd.DataFrame()

for d in data:
    record = {
        'city': d[0],
        'WAKA1': d[1],
        'WAKA2': d[2],
        '2019-01-01': d[3],
        '2019-01-02': d[4]
    }
    df = df.append(record, ignore_index=True)

在此处输入图片说明

Then let's filter it with data regex: 然后,使用数据正则表达式对其进行过滤:

df.filter(regex=('\\d{4}-\\d{2}-\\d{2}'))

在此处输入图片说明

After it, you can visualize filtered data with any viz library. 之后,您可以使用任何viz库可视化过滤的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM