I have a simple question. I have concatenated two dataframes with consistent columns. One of the column is entitled ‘isForecast’ where the top dataframe has a value of False, and for the dataframe it is True (I am adding a forecast to actuals data). From this point I put the data through a sklearn regression which is working but when I try to unpack the forecast I get an error.
allData = pd.concat([actuals, forecast])
allData = adjustment(allData,periodLength) #### this is a seperate function but the 'isForecast'column remains consistent.
forecastOutput = allData.query('isForecast').copy() ## error here
The error I am getting doesn’t make sense. My index is a column entitled ‘datetime’ and is not being referenced.
None of [Index([False, False, False, False, False, False, False, False, False, False,\n …\n True, True, True, True, True, True, True, True, True, True],\n dtype=’object’, name=’datetime’, length=91968)] are in the [index]
Any suggestions or comments
>Solution :
For me working your solution, alternative is compare by True:
allData = pd.DataFrame({'isForecast':[True, False, True]})
forecastOutput = allData.query('isForecast').copy()
print(forecastOutput)
isForecast
0 True
2 True
forecastOutput = allData.query('isForecast == True').copy()
print(forecastOutput)
isForecast
0 True
2 True
Or boolean indexing:
forecastOutput = allData[allData['isForecast']]
print(forecastOutput)
isForecast
0 True
2 True
If values are not boolean:
allData = pd.DataFrame({'isForecast':['True', 'False', 'True']})
forecastOutput = allData.query('isForecast == "True"').copy()
print(forecastOutput)
isForecast
0 True
2 True