Thursday, 3 January 2013

pandas notes

Extracting f0

x = store['spl20130409_107-6']
f0 = x.Freq[(x.SPL == max(x.SPL))]

:)

Extracting a results set by frequency range and node number from a store object (a dataFrame)

storeName = root + '20121205-WEEaxisymConstDispSettleTimes.h5'

store = pd.HDFStore(storeName)
x = store['ball70_p']
f = x.Freq[(x.Node == 32) & (x.Freq > fmin) & (x.Freq < fmax)].values
p = abs(x.Pressure[(x.Node == 32) & (x.Freq > fmin) & (x.Freq < fmax)]).values
store.close()

My observations suggest the store is volatile:  it should be closed when not in use to prevent database failure in case of, say,
power failure.  So it seems an open and close should be used in each ipython cell.  Wrap with, the open and close functions.

This seems clunky.  :(


Creating a dataFrame with column based data and appending new results without new columns,  with sort based on one of the columns.


for i in [4]:
    a = mfile.File(root2 + '1_hw%i.O07' % i); a.load()
    b = pd.DataFrame(a.pressures, columns = ['Freq', 'Node', 'Pressure'])
    c = store['v22_1_p'].append(b)
    c = c.sort_index(by = 'Freq')
    store['v22_1_p'] = c


Creating a multicolumn dataFrame with labels.


b = pd.DataFrame(array([x0[0, 1:], x0[1, 1:], x0[2, 1:], x0[3, 1:], x0[4, 1:]]).transpose(), 
        columns = ['Time', 'pNode4', 'pNode31', 'pNode32', 'pNode11', 'dNode35'])



Deleting an item in the store:

store.remove(keyName)

Adding a column to a dataFrame: (this does not work with the store)

b = pd.DataFrame(Q, columns = ['f0', 'DisplacementAtF0', 'Q'])  # create
b['newCol'] = listVariable   # append column



Printing a whole dataframe or specific columns

print melamine5cm.to_string()


    uMinMeas  uMaxMeas  uMeanMeas  dpMeas  uMeanSample  uErrorSample   resistivity       RError
0       0.03      0.03      0.030     5.4     0.003140      0.000000  17196.694215     0.000000
1       0.30      0.30      0.300    12.7     0.031401      0.000000   4044.407713     0.000000
2       0.15      0.19      0.170    19.7     0.017794      0.002093  11071.074380  1165.376251
3       0.54      0.68      0.610    27.1     0.063849      0.007327   4244.357133   436.919117
4       0.84      1.01      0.925    37.8     0.096821      0.008897   3904.114362   328.564080
5       0.97      1.01      0.990    46.0     0.103625      0.002093   4439.101761    87.903005
6       1.04      1.09      1.065    52.5     0.111475      0.002617   4709.579793   108.017885
7       1.24      1.31      1.275    61.7     0.133456      0.003663   4623.250689   123.521965
8       1.49      1.52      1.505    70.4     0.157530      0.001570   4468.982181    44.101798
9       1.61      1.68      1.645    78.1     0.172184      0.003663   4535.838629    94.496638
10      1.85      1.86      1.855    87.6     0.194165      0.000523   4511.621483    12.128015
11      1.89      1.95      1.920    94.6     0.200969      0.003140   4707.196970    72.418415
12      2.06      2.14      2.100   103.3     0.219810      0.004187   4699.519874    87.841493
13      2.29      2.34      2.315   111.9     0.242314      0.002617   4617.974760    49.337337


print melamine5cm.take([4, 5, 6, 7], axis=1)

    uMeanSample  uErrorSample   resistivity       RError
0      0.003140      0.000000  17196.694215     0.000000
1      0.031401      0.000000   4044.407713     0.000000
2      0.017794      0.002093  11071.074380  1165.376251
3      0.063849      0.007327   4244.357133   436.919117
4      0.096821      0.008897   3904.114362   328.564080
5      0.103625      0.002093   4439.101761    87.903005
6      0.111475      0.002617   4709.579793   108.017885
7      0.133456      0.003663   4623.250689   123.521965
8      0.157530      0.001570   4468.982181    44.101798
9      0.172184      0.003663   4535.838629    94.496638
10     0.194165      0.000523   4511.621483    12.128015
11     0.200969      0.003140   4707.196970    72.418415
12     0.219810      0.004187   4699.519874    87.841493
13     0.242314      0.002617   4617.974760    49.337337

Why that's double spaced I don't know!

Adjusting number of columns printed
pandas.set_option('display.max_columns', 50)





No comments:

Post a Comment