Removing a string in pandas with date indices, python

I am trying to remove the last line in dataframecreated by pandas in python, and it looks like you have problems.

index = DateRange('1/1/2000', periods=8)
df = DataFrame(randn(8, 3), index=index, columns=['A', 'B', 'C'])

I tried the drop method as follows:

df.drop([shape(df)[0]-1], axis = 0)

but he continues to say a label not contained in the axis.

I also tried to fall by index name and it still does not work.

Any advice would be appreciated. Thank!!!

+5
source share
2 answers
df.ix[:-1]

returns the original DataFrame with the last row removed.

+11
source

Linking to the DataFrame directly to retrieve all but the last index worked for me.

df[:-1]
+11
source

All Articles