pandas 中 DataFrame

来源:互联网 发布:公章制作软件 编辑:程序博客网 时间:2024/06/05 00:22

只是想记一下自己遇到的一些dataframe中刚开始碰到不会的地方。

>>> import pandas as pd>>> data = {'a':[1,2,3],'b':[4,5,6],'c':[7,8,9]}>>> frame = pd.DataFrame(data)>>> frame   a  b  c0  1  4  71  2  5  82  3  6  9>>> frame[frame['a']==2]['c'].values[0]8>>> frame[frame['a']==2]['c'].values[1]Traceback (most recent call last):  File "<stdin>", line 1, in <module>IndexError: index 1 is out of bounds for axis 0 with size 1
>>> data = {'a':[1,2,3],'b':[4,5,6],'c':[7,['m','n'],9]}>>> frame = pd.DataFrame(data)>>> frame[frame['a']==2]['c'].values[0]['m', 'n']>>> frame[frame['a']==2]['c'].values[1]Traceback (most recent call last):  File "<stdin>", line 1, in <module>IndexError: index 1 is out of bounds for axis 0 with size 1>>> frame[frame['a']==2]['c']1    [m, n]Name: c, dtype: object