2.4.dataの操作
2.5.indexの操作
2.6.columunsの操作
3.データの読み書き
Microsoft Windows [Version 10.0.18362.836] (c) 2019 Microsoft Corporation. All rights reserved. C:\Users\***> cd desktop C:\Users\***\Desktop > cd pandas_sample C:\Users\***\Desktop\pandas_sample >
C:\Users\***\Desktop\pandas_sample > python Python *.*.* (tags/v*.*.*:e********e, Jul * ****, **:**:**) [MSC v.**** 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>>
>>> import numpy as np >>> import pandas as pd
>>> df = pd.read_csv( 'sample1_1.csv' )
>>> df data1 data2 data3 0 0.000154 -0.037 1.300 1 0.000142 -0.036 0.100 2 0.000148 -0.036 0.120 ・・・(省略)・・・ 29 0.000118 -0.033 0.920 >>>
>>> ID = np.arange(1,31,1) >>> ID array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) >>>
>>> df.set_index( ID, inplace = True ) >>> df data1 data2 data3 1 0.000154 -0.037 1.300 2 0.000142 -0.036 0.100 3 0.000148 -0.036 0.120 ・・・(省略)・・・ 30 0.000118 -0.033 0.920 >>>
>>> df.loc[10] data1 0.000144 data2 -0.035000 data3 -0.150000 Name: 10, dtype: float64 >>>
>>> df[ 'data2' ] 0 -0.037 1 -0.036 ・・・(省略)・・・ 29 -0.033 Name: data2, dtype: float64 >>>
>>> df.loc[ 3 , 'data3' ] 0.12 >>>
>>> df data1 data2 data3 1 0.000154 -0.037 1.300 2 0.000142 -0.036 0.100 ・・・(省略)・・・ 30 0.000118 -0.033 0.920 >>> >>> df + 1 data1 data2 data3 1 1.000154 0.963 2.300 2 1.000142 0.964 1.100 ・・・(省略)・・・ 30 1.000118 0.967 1.920 >>>
>>> df data1 data2 data3 1 0.000154 -0.037 1.300 2 0.000142 -0.036 0.100 ・・・(省略)・・・ 30 0.000118 -0.033 0.920 >>> >>> df['data2'] = df['data2'] / 100 >>> df data1 data2 data3 1 0.000154 -0.00037 1.300 2 0.000142 -0.00036 0.100 ・・・(省略)・・・ 30 0.000118 -0.00033 0.920 >>>
>>> df data1 data2 data3 1 0.000154 -0.037 1.300 ・・・ >>> df.loc[1].mean() 0.43326133333333333 >>>
>>> df['data3'].sum() -7.164999999999999 >>>
>>> df data1 data2 data3 0 0.000154 -0.037 1.300 1 0.000142 -0.036 0.100 2 0.000148 -0.036 0.120 ・・・ >>> df2 data1 data2 data3 0 0.000308 -0.074 2.600 1 0.000284 -0.072 0.200 2 0.000296 -0.072 0.240 ・・・ >>> df + df2 data1 data2 data3 0 0.000462 -0.111 3.900 1 0.000426 -0.108 0.300 2 0.000444 -0.108 0.360 ・・・