0

I have this code and I supposed to organize the number in 'Data 1' column alphabetically from [3,4,1] to [1,3,4] without changing the data. How do I do that?

import numpy as np
import pandas as pd 
# TODO: 

data = pd.DataFrame({"Data 1": [3,4,1]})
data

Output:

    Data 1
0   3
1   4
2   1

The output I wanted:

Data 1
0   1
1   3
2   4
Henry Davis
  • 101
  • 1
  • 9
  • What do you mean by *without changing the data*? if your input is a list, simpy sort the list first? `pd.DataFrame({"Data 1": sorted([3,4,1])})` – anky Dec 25 '21 at 13:01
  • 1
    Does this answer your question? [how to sort pandas dataframe from one column](https://stackoverflow.com/questions/37787698/how-to-sort-pandas-dataframe-from-one-column) – Subbu VidyaSekar Dec 25 '21 at 13:02
  • @anky , That basically mean without changing the number inside the bracket. By the way you answered my question and its works thank you – Henry Davis Dec 25 '21 at 13:03
  • @Dan then you can also use `data.sort_values(by='Data 1')` as well, as mentioned in the duplicate link – anky Dec 25 '21 at 13:05

0 Answers0