gas_df.loc[:-1,['date','psv-ttf_spot','psv-cegh_spot', 'psv-peg_spot','ttf-cegh_spot', 'ttf-peg_spot','cegh-peg_spot']] this does not give the last row in python

To select all rows except the last one in a pandas DataFrame using .loc indexing, you can use the following code:

main.py
gas_df.loc[:-1, ['date','psv-ttf_spot','psv-cegh_spot', 'psv-peg_spot','ttf-cegh_spot', 'ttf-peg_spot','cegh-peg_spot']]
121 chars
2 lines

However, if it's not giving you the last row, it's possible that the index of your DataFrame is not sequential. In that case, you can reset the index and then use .loc indexing:

main.py
gas_df.reset_index(drop=True).loc[:-1, ['date','psv-ttf_spot','psv-cegh_spot', 'psv-peg_spot','ttf-cegh_spot', 'ttf-peg_spot','cegh-peg_spot']]
144 chars
2 lines

This will create a new DataFrame with the index reset and exclude the last row.

related categories

gistlibby LogSnag