<Python, pandas> è¡(row)ã追å ããã
è¡row
ã追å ãããè¡ã®è¿½å ã
ãããããã¼ã¿ãã¬ã¼ã DataFrame
ããã£ãæã
In [71]: df Out[71]: id name birthday is_relative 0 1 Hage 1960-01-01 1 1 2 Hige 1960-01-02 1
ï¼è¡è¿½å ãããæã¯ãã·ãªã¼ãºSeries
ã§ãã¼ã¿ä½ã£ã¦ã.append()
ããã°ããã£ã½ãã
ãã£ã¦ã¿ãã
In [74]: se = pd.Series([3, 'Hoge', date(1960,1,3), 1], index=df.columns) In [75]: se Out[75]: id 3 name Hoge birthday 1960-01-03 is_relative 1 dtype: object In [76]: df.append(se, ignore_index=True) Out[76]: id name birthday is_relative 0 1 Hage 1960-01-01 1 1 2 Hige 1960-01-02 1 2 3 Hoge 1960-01-03 1
ã«ããã»ã©ã
18/09/03 追å
ä»ã®ãã¤ã¹ãªããæ¹ãå¦ãã ã®è¿½å ããã£ã¡ã
DataFrame.loc
ã使ããªãã
loc[hoge]
ã§hoge
è¡ãé¸æã§ããã®ã§ãããã«å¤ã®ãªã¹ããæµãè¾¼ãã°ããã£ãã¼ï¼ãã²ãã£ã»ãï¼
In [33]: import pandas as pd In [34]: import io In [35]: data = ''' ...: a b c d e ...: 1 2 3 4 5 ...: 6 7 8 9 10 ...: ''' In [36]: df = pd.read_table(io.StringIO(data), sep=' ') In [37]: df Out[37]: a b c d e 0 1 2 3 4 5 1 6 7 8 9 10 In [38]: df.loc[0] Out[38]: a 1 b 2 c 3 d 4 e 5 Name: 0, dtype: int64 In [40]: df.loc[3] = [i for i in range(100,105)] In [41]: df Out[41]: a b c d e 0 1 2 3 4 5 1 6 7 8 9 10 3 100 101 102 103 104