jeffalstott / powerlaw

600 stars 132 forks source link

returns datatype error #58

Closed ghost closed 6 years ago

ghost commented 6 years ago

Here is my code:

newDS=removeTotal[['Firms', 'IndustrySize']][:8].astype(float)

Firms   IndustrySize
1   3598185.0   1.0
2   998953.0    2.0
3   608502.0    3.0
4   5205640.0   4.0
5   513179.0    5.0
6   87563.0 6.0
7   5806382.0   7.0
8   19076.0 8.0
import matplotlib.pyplot as plt
plt.plot(newDS['Firms'],newDS['IndustrySize'] )
plt.show()

plot is generated okay.

Now if I run

from powerlaw import plot_pdf, Fit, pdf x, y = pdf(newDS)

it generates following error, traceback provided below:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-21-79cc0ba3a245> in <module>()
      1 from powerlaw import plot_pdf, Fit, pdf
----> 2 x, y = pdf(newDS)

/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/powerlaw.py in pdf(data, xmin, xmax, linear_bins, **kwargs)
   1949 
   1950 
-> 1951     if xmin<1:  #To compute the pdf also from the data below x=1, the data, xmax and xmin are rescaled dividing them by xmin.
   1952         xmax2=xmax/xmin
   1953         xmin2=1

TypeError: '<' not supported between instances of 'str' and 'int' I also have asked it here

ghost commented 6 years ago

I have tried to use int, str, int64 in converting the dataframe objects to datatypes

jeffalstott commented 6 years ago

I'm not quite sure what the intention is here. powerlaw does not receive histogram inputs. powerlaw receives a list or array of raw data (e.g. [8,8,8,8,8,1,1,1,1,...2,3,4,7]). It does not take dataframes or dictionaries or histograms or whatnot.

On Sun, Jun 3, 2018 at 3:50 PM, dataneupane notifications@github.com wrote:

Here is my code:

newDS=removeTotal[['Firms', 'IndustrySize']][:8].astype(float)

Firms IndustrySize 1 3598185.0 1.0 2 998953.0 2.0 3 608502.0 3.0 4 5205640.0 4.0 5 513179.0 5.0 6 87563.0 6.0 7 5806382.0 7.0 8 19076.0 8.0

import matplotlib.pyplot as plt plt.plot(newDS['Firms'],newDS['IndustrySize'] ) plt.show()

plot is generated okay.

Now if I run

from powerlaw import plot_pdf, Fit, pdf x, y = pdf(newDS)

it generates following error, traceback provided below:


TypeError Traceback (most recent call last)

in () 1 from powerlaw import plot_pdf, Fit, pdf ----> 2 x, y = pdf(newDS) /usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/powerlaw.py in pdf(data, xmin, xmax, linear_bins, **kwargs) 1949 1950 -> 1951 if xmin<1: #To compute the pdf also from the data below x=1, the data, xmax and xmin are rescaled dividing them by xmin. 1952 xmax2=xmax/xmin 1953 xmin2=1 *TypeError: '<' not supported between instances of 'str' and 'int'* — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub , or mute the thread .
ghost commented 6 years ago

thanks jeffalstott. Yes, I did not first check it. Later realized I were supplying wrong data but not the dtypes and it works as it is intended to.