1

我有一个数据框对象,df 如下:

<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 4460 entries, 2013-04-02 00:24:14.655000 to 2013-05-01 08:05:37.820000
Columns: 3928 entries, 0.36813255,37.5913675 to 9.99963814285,76.3137843191
dtypes: float64(3928)

df.plot() 给了我

ValueError: x and y must have same first dimension

数据框中没有 NaN 值。奇怪的是,数据框的某些范围确实绘制得很好。例如以下作品:

df.ix[:,:3].plot()

知道会发生什么吗?

编辑:

样本数据:

lat_lng                     0.36813255,37.5913675  1.33731422941,103.965656679
date                                                                          
2013-04-02 00:24:14.655000                      0                            0
2013-04-02 08:05:39.719000                      0                            1
2013-04-02 08:16:56.986000                      0                            0
2013-04-02 08:18:00.408000                      0                            0
2013-04-02 08:18:38.530000                      10                           0
2013-04-02 08:24:02.663000                      0                            0
2013-04-02 08:24:27.286000                      0                            0
2013-04-02 08:24:46.466000                      0                            1
2013-04-02 08:25:32.366000                      0                            0
2013-04-02 08:25:52.018000                      0                            0

这不会绘制:

lat_lng                     0.36813255,37.5913675  1.33731422941,103.965656679  1.36110856929,103.886645147  10.0001097537,76.3023939556
date                                                                                                                                    
2013-04-02 00:24:14.655000                      0                            0                            0                            0
2013-04-02 08:05:39.719000                      0                            0                            0                            0
2013-04-02 08:16:56.986000                      0                            0                            0                            0
2013-04-02 08:18:00.408000                      0                            0                            0                            0
2013-04-02 08:18:38.530000                      0                            0                            0                            0
2013-04-02 08:24:02.663000                      0                            0                            0                            0
2013-04-02 08:24:27.286000                      0                            0                            0                            0
2013-04-02 08:24:46.466000                      0                            0                            0                            0
2013-04-02 08:25:32.366000                      0                            0                            0                            0
2013-04-02 08:25:52.018000                      0                            0                            0                            0
4

2 回答 2

1

我有同样的错误消息,原因是列名是数字而不是文本!

于 2013-05-07T15:46:16.447 回答
0

列名有问题(太长?)...我可以确认您的第二个示例不会在 0.11 上绘制

如果您使用范围,这会很好地绘制:

df.columns = range(4)

如果您使用 MultiIndex / 更精细的东西,也可以很好地绘制:

In [10]: pd.MultiIndex.from_tuples(map(lambda X: [float(x) 
                                                  for x in X.split(',')],
                                        df.columns),
                                   names=['lat', 'long'])

Out[11]:
MultiIndex
[(0.36813255, 37.5913675), (1.33731422941, 103.965656679), (1.36110856929, 103.886645147), (10.0001097537, 76.3023939556)

In [12]: df1.columns = Out[11]

In [13]: df1
Out[13]:
lat                          0.368133    1.337314    1.361109    10.000110
long                        37.591367   103.965657  103.886645  76.302394
date
2013-04-02 00:24:14.655000           0           0           0           0
2013-04-02 08:05:39.719000           0           0           0           0
2013-04-02 08:16:56.986000           0           0           0           0
2013-04-02 08:18:00.408000           0           0           0           0
2013-04-02 08:18:38.530000           0           0           0           0
2013-04-02 08:24:02.663000           0           0           0           0
2013-04-02 08:24:27.286000           0           0           0           0
2013-04-02 08:24:46.466000           0           0           0           0
2013-04-02 08:25:32.366000           0           0           0           0
2013-04-02 08:25:52.018000           0           0           0           0

(这也很好。)

于 2013-05-07T15:47:09.630 回答