Answer the question
In order to leave comments, you need to log in
Why doesn't sort_values work in pandas?
Gentlemen, why can't panda's sort_values work? I need to do a couple of df manipulations, the first one is sorting by weight. However, it doesn't want to sort.
df = pd.read_csv(file_name,delimiter=';')
df['Box_weight'] = df['Box_weight'].str.replace(',','.')
df['Box_volume'] = df['Box_volume'].str.replace(',','.')
df['Box_weight'] = pd.to_numeric(df.Box_weight, errors='coerce')
df['Box_volume'] = pd.to_numeric(df.Box_volume, errors='coerce')
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 748 entries, 0 to 747
Data columns (total 11 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Index 748 non-null int64
1 Место 748 non-null object
2 Ярус 748 non-null int64
3 № артикула 748 non-null int64
4 Описание 748 non-null object
5 Box_weight 748 non-null float64
6 Box_volume 748 non-null float64
7 Статус 748 non-null object
8 АВС код 748 non-null object
9 Область 748 non-null int64
10 Категория 748 non-null object
dtypes: float64(2), int64(4), object(5)
memory usage: 64.4+ KB
df.sort_values(by=['Box_weight'],ascending=True)
df['Box_weight'].head(20)
0 0.500
1 0.500
2 1.000
3 1.000
4 1.000
...
15 4.914
16 0.500
17 0.500
18 1.000
19 1.000
Answer the question
In order to leave comments, you need to log in
By default, this method returns a sorted df. See the inplace argument
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question