0

I have pandas dataframe with several column from which one of them is called Pnum. I am trying to create new dataframe by filtering out some of the values from original.

I used this line to accomplish that:

data = df.loc[df["PNum"] < 10000]

Now my next step is to convert my date value in proper datetime and also create column YearMonth for which I have used these line of code:

data["DateOut"] = pd.to_datetime(data["DateOut"], format='%Y-%m-%d')
data["YearMonth"] = pd.to_datetime(data['DateOut']).dt.to_period('M')

This gives me the results that seems right however i also get this warning:

A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

I have tried to do some research on this but I am unable to find the solution that will satisfy those warnings. Any suggestions?

Slavisha84
  • 747
  • 3
  • 7
  • 22

0 Answers0