When I try to take one series from dataframe I get this issue
anaconda3/lib/python3.6/site-packages/numpy/core/fromnumeric.py:52: FutureWarning: reshape is deprecated and will raise in a subsequent release. Please use .values.reshape(...) instead
return getattr(obj, method)(*args, **kwds)
This is the code snippet
for idx, categories in enumerate(categorical_columns):
ax = plt.subplot(3,3,idx+1)
ax.set_xlabel(categories[0])
box = [df[df[categories[0]] == atype].price for atype in categories[1]]
ax.boxplot(box)
For avoid chained indexing use DataFrame.loc:
box = [df.loc[df[categories[0]] == atype, 'price'] for atype in categories[1]]
And for remove FutureWarning is necessary upgrade pandas with matplotlib.
Related
df = pd.DataFrame(columns=['locale', 'description'])
for text in texts:
df = pd.concat(
dict(
locale=text.locale,
description=text.description
),
ignore_index=True
)
Are there any workaround for this? It was supposed to work with df.append but it says FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
I work with pandas dataframes and want to create a function with indexing.
def func(L,ra,N):
df_N = df[T_N].diff()
df[T_N] = df[T_N].iloc[df_N.index.min():df_N.index.max()]
df[T_N] = df[T_N].mean()
Value = [L,df[TR[0]].iloc[1]-(df[T_N[0]].iloc[1]-df[T_N[0]].iloc[1]),1]
return Value
For the line
df[T_N] = df[T_N].iloc[df_N.index.min():df_N.index.max()]
The error
TypeError: cannot do positional indexing on Int64Index with these indexers [nan] of type float
occurs. Does anyone know a way how I can avoid that? Is it even possible to do it that way? It works at other lines, just this one seems to be a problem.
I have a pandas dataframe with two columns. One of the columns contains one nan value. Creating a histogram gives no warnings, but creating a boxplot gives a numpy VisibleDeprecationWarning. I use this in class and it worked fine the last couple of years. Advantage of pandas was always that hist and boxplot worked on data with nans. Current version that throws the error: numpy 1.19.1. pandas 1.1.0. Is this the intended behavior? Mismatch between versions? Example code:
%matplotlib inline
import numpy as np
import pandas as pd
data = pd.DataFrame()
data['test1'] = np.random.normal(size=100)
data['test2'] = np.random.normal(size=100)
data.test1[5] = np.nan # set one value to nan
data.boxplot() # throws VisibleDeprecationWarning
Warning:
/anaconda3/lib/python3.8/site-packages/numpy/core/_asarray.py:83: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray return array(a, dtype, copy=False, order=order)
The combination of numpy 1.19.1. pandas 1.1.0 gives the warning. Warning disappears after updating to latest version (in this case numpy 1.19.2 and pandas 1.1.3).
As described here, Pandas.sort_index() sometimes emits a FutureWarning when doing a sort on a DateTimeIndex. That question isn't actionable, since it contains no MCVE. Here's one:
import pandas as pd
idx = pd.DatetimeIndex(['2017-07-05 07:00:00', '2018-07-05 07:15:00','2017-07-05 07:30:00'])
df = pd.DataFrame({'C1':['a','b','c']},index=idx)
df = df.tz_localize('UTC')
df.sort_index()
The warning looks like:
FutureWarning: Converting timezone-aware DatetimeArray to
timezone-naive ndarray with 'datetime64[ns]' dtype
The stack (Pandas 0.24.1) is:
__array__, datetimes.py:358
asanyarray, numeric.py:544
nargsort, sorting.py:257
sort_index, frame.py:4795
The error is emitted from datetimes.py, requesting that it be called with a dtype argument. However, there's no way to force that all the way up through nargsort -- it looks like obeying datetimes.py's request would require changes to both pandas and numpy.
Reported here. In the meantime, can you think of a workaround that I've missed?
Issue confirmed for the 0.24.2 milestone. Workaround is to filter the warning, thus:
with warnings.catch_warnings():
# Pandas 0.24.1 emits useless warning when sorting tz-aware index
warnings.simplefilter("ignore")
ds = df.sort_index()
I use the following function to encode the categorical features of my dataset (it has 27 features where 11 of them is categorical):
from sklearn import preprocessing
def features_encoding(data):
columnsToEncode = list(data.select_dtypes(include=['category', 'object']))
le = preprocessing.LabelEncoder()
for feature in columnsToEncode:
try:
data[feature] = le.fit_transform(data[feature])
except:
continue
return data
But I get this error:
FutureWarning: numpy not_equal will not check object identity in the future. The comparison did not return the same result as suggested by the identity (`is`)) and will change.
flag = np.concatenate(([True], aux[1:] != aux[:-1]))
I don't understand this error. Kindly, can someone explain what is it about and how to fix it?
This is almost certainly being caused by there being np.nan more than once in an array of dtype=object that is passed into np.unique.
This may help clarify what's going on:
>>> np.nan is np.nan
True
>>> np.nan == np.nan
False
>>> np.array([np.nan], dtype=object) == np.array([np.nan], dtype=object)
FutureWarning: numpy equal will not check object identity in the future. The comparison did not return the same result as suggested by the identity (`is`)) and will change.
array([ True], dtype=bool)
So when comparing two arrays of dtype=object, numpy checks if the return of the comparison function is False when both objects being compared are the exact same. Because right now it assumes that all objects compare equal to themselves, but that will be changed at same time in the future.
All in all, it's just a warning, so you can ignore it, at least for now...