I have a data frame, extracted from a .csv file using
Data = pandas.read_csv
One of the columns of the data frame are dates, such as
'14/09/2015', the type of data is
I need to create a subset, for which I use:
NewDataFrame = DataFrame['DatesColumn'][DataFrame['DatesColumn']==desired date]
But I have two main problems:
KeyError : -1L
I tried to use this code to select 2014:
NewDataFrame = DataFrame['DatesColumn'][DataFrame['DatesColumn'][-1]==4]
forloop to transform the data, I get the error:
TypeError: 'float' object has no attribute '__getitem__'
Q: How can I subset the data (or clean it) by year?
NaN values you can use
# to fill NaNs with zeros noNans = withNans.fillna(0)
And for the date issue,
instead of handling the date strings yourself you should let the already
existing libraries handle them for you. In this case the
can do it for you.
See the documentation
Here's a little example:
1,14/09/2016,dataa 1,14/09/2015,dataa 2,14/10/2014,dataa2
import pandas as pd from datetime import date df = pd.read_csv("test.csv", header=None, parse_dates=) df[df > date.today()]
0 1 2 0 1 2016-09-14 dataa