Question: Newbie to pandas,

after searching I found pandas is very suitable to make my data divided by parts for further display on charts.

Here is what I do with it:

```
print pd.cut(data_lst, 5).value_counts()

```

the `data_lst` is a list of numbers and above line of code give a pretty neat result like this which is exactly what I need:

```
(-0.513, 25.6]      9
(25.6, 51.2]       43
(51.2, 76.8]      160
(76.8, 102.4]       0
(102.4, 128.0]    302

```

but I just want the result to be a dict as the format of:

```
{
 "(-0.513, 25.6]":9,
 "(25.6, 51.2]":43,
 "(51.2, 76.8]":160,
 "(76.8, 102.4]":0,
 "(102.4, 128.0]":302    
}

```

So that I could save that to the database, but I couldn't find a way to get that result other than print the `value_counts()` out.

Answer: 
save the printed item to a variable and convert that dataframe to dict.

df=( pd.cut(data\_lst, 5).value\_counts())

dict\_n=df.to\_dict()
I believe this will help..

Just taking an example DataFrame using..

See this [Documentation pandas.DataFrame.to\_dict](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_dict.html)

```
>>> df = pd.DataFrame({'a': ['red', 'yellow', 'blue'], 'b': [0.5, 0.25, 0.125]})
>>> df
        a      b
0     red  0.500
1  yellow  0.250
2    blue  0.125

```

**dict - the default: column names are keys, values are dictionaries of index:data pairs**

```
>>> df.to_dict('dict')
{'a': {0: 'red', 1: 'yellow', 2: 'blue'}, 'b': {0: 0.5, 1: 0.25, 2: 0.125}}

```

**list - keys are column names, values are lists of column data**

```
>>> df.to_dict('list')
{'a': ['red', 'yellow', 'blue'], 'b': [0.5, 0.25, 0.125]}

```

**If you like tuple like values then try below:**

```
>>> {x[0]: x[1:] for x in df.itertuples(index=False)}
{'red': (0.5,), 'yellow': (0.25,), 'blue': (0.125,)}

```