1

I am trying to do a numeric sort by column "DayOfYear' but it is not allowing me to. I converted it into a dataframe with pandas but I have had no luck with the numeric sorting.

  results7 = ([['1', '660.206159375', '2200.969', '1588.2815', '831.8674',
    '521.3459', '329.77015', '205.89374', '102.9523'],
   ['10', '932.475360938', '2381.846', '2098.8083', '1289.0055',
    '780.2308', '522.78565', '340.15073', '298.4486'],
   ['11', '914.067898437', '2698.957', '1922.7277', '1259.1625',
    '731.6858', '505.171', '267.1976', '203.4595'],
   ['12', '786.08815', '2580.748', '1823.5057', '908.63865',
    '652.7224', '455.6254', '229.1738', '146.3479'],
   ['2', '928.879345312', '3075.417', '2560.8875', '1166.789',
    '734.7388', '512.9898', '241.98641', '167.2151'],
  ['', nan, nan, nan, nan, nan, nan, nan, nan]], dtype=object
   ])

names50 = ['DayOfYear','AvgFlow','Max','n95th','n75th','n50th','n25th','n5th','Min']
results9 = pd.DataFrame(results8,columns=names50)
results10 = results9.astype(str).convert_objects(convert_numeric=True)

results11 = results10[~np.isnan(results10).any(axis = 1)]
results12 = np.sort(results11, order = 'DayOfYear')

I received an error message of

ValueError: Cannot specify order when the array has no fields.

Did I not specify the fields when I converted it to a pd.DataFrame? Also when I try to do a .dtype I receive an error message:

AttributeError: 'DataFrame' object has no attribute 'dtype'

What am I doing wrong here?

4
  • Is that really results7 defined at the top? If so, can you provide a definition for results8 (the one being passed to the DataFrame constructor)? Commented Mar 2, 2015 at 16:34
  • Your current post code does not reproduce your error, or at least I can't run it, can you post minimal code to reproduce your errors Commented Mar 2, 2015 at 16:34
  • DataFrames don't have 'dtype', DataFrame columns do. Commented Mar 2, 2015 at 16:35
  • DataFrames have attribute 'dtypes' that will return the 'dtype' for each of its series Commented Mar 2, 2015 at 16:39

1 Answer 1

2

1) Use the DataFrames dtypes attribute. It returns the dtype attribute for each of its Series.

http://pandas.pydata.org/pandas-docs/dev/generated/pandas.DataFrame.dtypes.html#pandas.DataFrame.dtypes

2) Just use pandas' sort...

results11.sort('DayOfYear')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.