Python pandas find starting/ending row and rounding numbers
Question: 
    import pandas as pd
    import numpy as np
    import urllib
    
    url = 'http://cawcr.gov.au/staff/mwheeler/maproom/RMM/RMM1RMM2.74toRealtime.txt'
    urllib.urlretrieve(url,'datafile.txt')
    
    df = pd.read_table('datafile.txt', sep='\s+', header=None)
    df.columns = ['year', 'month', 'day', 'n1', 'n2', 'n3', 'n4', 'type']
    df = df[df.year > 1978] #new starting row is created, how do I find what the new starting row is
    df = df[df.type < 'Prelim_value'] #new ending row is created, how do I find what the new ending row is
    
    tda1 = []
    for a in range(starting_row, ending_row):
        if a < starting_row+19:
            tda1.append(0.0)
        else:
            ch = df.ix[a:a+20, ['n1']]
            dc = np.round(ec,0)
            tda1.append(ec)
    

How do I find the starting row after chopping off the beginning of the file,
ditto on finding the ending row?

Would I need to create a whole new dataframe if I wanted to keep everything
together...aka, I want to have tda1 being right in line with n1. If I access
`tda1[1700]` and `n1[1700]` I want them to both be pointing to the same date.

As of yet I still can't get `df.iloc(0)['n1']` or any other combo of to give
me anything other than an error suggesting that DataFrame object is not an
attribute of iloc.


Answer: To quickly answer your last question, use:

    
    
    import numpy as np
    np.round(ec, 0)
    

For your first (series of) question(s), you don't give us any data to play
with and your questions isn't very clear. Either way, you can always get the
the first and last rows of _any_ dataframe with `df.iloc[0]` and
`df.iloc[-1]`, respectively.

### Edits:

If you simply need to know how many rows you have, use `df.shape`. Here's a
toy example:

    
    
    import pandas
    
    df = pandas.DataFrame([
        (1977, 1, 1),
        (1978, 1, 2),
        (1979, 1, 3),
        (1980, 1, 4),
        (1977, 2, 1),
        (1978, 2, 2),
        (1979, 2, 3),
        (1980, 2, 4),
        (1977, 3, 1),
        (1978, 3, 2),
        (1979, 3, 3),
        (1980, 3, 4),
    ], columns=['year', 'a', 'b'])
    print(df.to_string())
    

Which prints:

    
    
        year  a  b
    0   1977  1  1
    1   1978  1  2
    2   1979  1  3
    3   1980  1  4
    4   1977  2  1
    5   1978  2  2
    6   1979  2  3
    7   1980  2  4
    8   1977  3  1
    9   1978  3  2
    10  1979  3  3
    11  1980  3  4
    

And then:

    
    
    df = df[df.year > 1978]
    df = df[df.a < 3]
    print(df.to_string())
    

which gives:

    
    
       year  a  b
    2  1979  1  3
    3  1980  1  4
    6  1979  2  3
    7  1980  2  4
    

Try this our yourself after executing everything above:

    
    
    print(df.shape)
    
    for row in range(df.shape[0]-1):
        print(df.iloc[row])
    

### For rounding:

    
    
    df = pandas.DataFrame(np.random.normal(size=(4,4)))
    rounded = np.round(df,1)
    print(rounded.to_string())
         0    1    2    3
    0 -1.2  1.9  0.7 -0.8
    1 -0.5  0.9  1.6 -0.3
    2  0.4 -0.2 -1.6 -0.2
    3 -1.7  1.1  0.1 -0.6
    

