Python Forum
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
describe top
#1
Sad

I import pandas and read my data file. describe says that top is divide by zero for Perc Ch column and it does not give some of the statistic it usually does. Later when I try to do a histogram for this column, it gives me error messages. It will graph the normal distribution alone, but nothing I tried so far will let it do a histogram for the Perc Ch column.

import pandas as pd
priceChanges = pd.read_csv('BitcoinAll111618.csv', sep=',')
priceChanges.head(15)
Date Open High Low Close Volume Day Change Perc Ch
0 7/16/2010 0.04951 0.04951 0.04951 0.04951 0 NaN 0.000
1 7/17/2010 0.04951 0.08585 0.05941 0.08584 5 0.03633 0.000
2 7/18/2010 0.08584 0.09307 0.07723 0.08080 49 -0.00504 -0.139
3 7/19/2010 0.08080 0.08181 0.07426 0.07474 20 -0.00606 1.202
4 7/20/2010 0.07474 0.07921 0.06634 0.07921 42 0.00447 -0.738
5 7/21/2010 0.07921 0.08181 0.05050 0.05050 129 -0.02871 -6.423
6 7/22/2010 0.05050 0.06767 0.05050 0.06262 141 0.01212 -0.422
7 7/23/2010 0.06262 0.06161 0.05049 0.05454 26 -0.00808 -0.667
8 7/24/2010 0.05454 0.05941 0.05050 0.05050 85 -0.00404 0.500
9 7/25/2010 0.05050 0.05600 0.05000 0.05600 46 0.00550 -1.361
10 7/26/2010 0.05600 0.06050 0.05300 0.06000 196 0.00400 0.727
11 7/27/2010 0.06000 0.06200 0.05400 0.05890 255 -0.00110 -0.275
12 7/28/2010 0.05890 0.06990 0.05710 0.06990 528 0.01100 -10.000
13 7/29/2010 0.06990 0.06980 0.05820 0.06270 198 -0.00720 -0.655
14 7/30/2010 0.06270 0.06889 0.05600 0.06785 243 0.00515 -0.715
priceChanges['Perc Ch'].describe()
count 3038
unique 2247
top #DIV/0!
freq 41
Name: Perc Ch, dtype: object

import random
import numpy
from matplotlib import pyplot
pyplot.style.use('seaborn-deep')

#x = [random.gauss(3,1) for _ in range(400)]
#y = [random.gauss(4,2) for _ in range(400)]

bins = 100
#pyplot.hist(data, bins, alpha=0.5, label='x')

pc=numpy.array(priceChanges['Perc Ch'])
plt.figure(figsize=(20,10))
pyplot.hist([pc,data],bins,label=["SignedPrice Changes as Percent of Previous Day","Normal Distribution"])
SMALL_SIZE = 12
MEDIUM_SIZE = 14
BIGGER_SIZE = 20

plt.rc('font', size=MEDIUM_SIZE) # controls default text sizes
plt.rc('axes', titlesize=BIGGER_SIZE) # fontsize of the axes title
plt.rc('axes', labelsize=MEDIUM_SIZE) # fontsize of the x and y labels
plt.rc('xtick', labelsize=SMALL_SIZE) # fontsize of the tick labels
plt.rc('ytick', labelsize=SMALL_SIZE) # fontsize of the tick labels
plt.rc('legend', fontsize=MEDIUM_SIZE) # legend fontsize
plt.rc('figure', titlesize=BIGGER_SIZE) # fontsize of the figure t
plt.title("Frequency Distribution of Bitcoin vs $ Change in a Day 7/16/10 - 11/9/18 versus Normal Distribution")
plt.xlabel('One Day Change In Value $')
plt.ylabel('Number of Days')
pyplot.legend(loc='upper right')
pyplot.show()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-14-84f9c0bd2a25> in <module>()
12 pc=numpy.array(priceChanges['Perc Ch'])
13 plt.figure(figsize=(20,10))
---> 14 pyplot.hist([pc,data],bins,label=["SignedPrice Changes as Percent of Previous Day","Normal Distribution"])
15 SMALL_SIZE = 12
16 MEDIUM_SIZE = 14

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\pyplot.py in hist(x, bins, range, density, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, normed, hold, data, **kwargs)
3023 histtype=histtype, align=align, orientation=orientation,
3024 rwidth=rwidth, log=log, color=color, label=label,
-> 3025 stacked=stacked, normed=normed, data=data, **kwargs)
3026 finally:
3027 ax._hold = washold

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\__init__.py in inner(ax, *args, **kwargs)
1715 warnings.warn(msg % (label_namer, func.__name__),
1716 RuntimeWarning, stacklevel=2)
-> 1717 return func(ax, *args, **kwargs)
1718 pre_doc = inner.__doc__
1719 if pre_doc is None:

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in hist(***failed resolving arguments***)
6147 for xi in x:
6148 if len(xi) > 0:
-> 6149 xmin = min(xmin, xi.min())
6150 xmax = max(xmax, xi.max())
6151 bin_range = (xmin, xmax)

C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\_methods.py in _amin(a, axis, out, keepdims)
27
28 def _amin(a, axis=None, out=None, keepdims=False):
---> 29 return umr_minimum(a, axis, None, out, keepdims)
30
31 def _sum(a, axis=None, dtype=None, out=None, keepdims=False):

TypeError: '<=' not supported between instances of 'float' and 'str'
Reply
#2
Please put your code in Python code tags and full error traceback message in error tags. You can find help here.
Reply
#3
I do not see an edit button. How do I edit it? Thank you!
Reply
#4
(Nov-19-2018, 04:27 PM)JerryGraham Wrote: Sad

I import pandas and read my data file. describe says that top is divide by zero for Perc Ch column and it does not give some of the statistic it usually does. Later when I try to do a histogram for this column, it gives me error messages. It will graph the normal distribution alone, but nothing I tried so far will let it do a histogram for the Perc Ch column.

import pandas as pd
priceChanges = pd.read_csv('BitcoinAll111618.csv', sep=',')
priceChanges.head(15)
Output:
Date Open High Low Close Volume Day Change Perc Ch 0 7/16/2010 0.04951 0.04951 0.04951 0.04951 0 NaN 0.000 1 7/17/2010 0.04951 0.08585 0.05941 0.08584 5 0.03633 0.000 2 7/18/2010 0.08584 0.09307 0.07723 0.08080 49 -0.00504 -0.139 3 7/19/2010 0.08080 0.08181 0.07426 0.07474 20 -0.00606 1.202 4 7/20/2010 0.07474 0.07921 0.06634 0.07921 42 0.00447 -0.738 5 7/21/2010 0.07921 0.08181 0.05050 0.05050 129 -0.02871 -6.423 6 7/22/2010 0.05050 0.06767 0.05050 0.06262 141 0.01212 -0.422 7 7/23/2010 0.06262 0.06161 0.05049 0.05454 26 -0.00808 -0.667 8 7/24/2010 0.05454 0.05941 0.05050 0.05050 85 -0.00404 0.500 9 7/25/2010 0.05050 0.05600 0.05000 0.05600 46 0.00550 -1.361 10 7/26/2010 0.05600 0.06050 0.05300 0.06000 196 0.00400 0.727 11 7/27/2010 0.06000 0.06200 0.05400 0.05890 255 -0.00110 -0.275 12 7/28/2010 0.05890 0.06990 0.05710 0.06990 528 0.01100 -10.000 13 7/29/2010 0.06990 0.06980 0.05820 0.06270 198 -0.00720 -0.655 14 7/30/2010 0.06270 0.06889 0.05600 0.06785 243 0.00515 -0.715
priceChanges['Perc Ch'].describe()
Output:
count 3038 unique 2247 top #DIV/0! freq 41 Name: Perc Ch, dtype: object
import random
import numpy
from matplotlib import pyplot
pyplot.style.use('seaborn-deep')

#x = [random.gauss(3,1) for _ in range(400)]
#y = [random.gauss(4,2) for _ in range(400)]

bins = 100
#pyplot.hist(data, bins, alpha=0.5, label='x')

pc=numpy.array(priceChanges['Perc Ch'])
plt.figure(figsize=(20,10))
pyplot.hist([pc,data],bins,label=["SignedPrice Changes as Percent of Previous Day","Normal Distribution"])
SMALL_SIZE = 12
MEDIUM_SIZE = 14
BIGGER_SIZE = 20

plt.rc('font', size=MEDIUM_SIZE)          # controls default text sizes
plt.rc('axes', titlesize=BIGGER_SIZE)     # fontsize of the axes title
plt.rc('axes', labelsize=MEDIUM_SIZE)    # fontsize of the x and y labels
plt.rc('xtick', labelsize=SMALL_SIZE)    # fontsize of the tick labels
plt.rc('ytick', labelsize=SMALL_SIZE)    # fontsize of the tick labels
plt.rc('legend', fontsize=MEDIUM_SIZE)    # legend fontsize
plt.rc('figure', titlesize=BIGGER_SIZE)  # fontsize of the figure t
plt.title("Frequency Distribution of Bitcoin vs $ Change in a Day  7/16/10 - 11/9/18 versus Normal Distribution")
plt.xlabel('One Day Change In Value $')
plt.ylabel('Number of Days')             
pyplot.legend(loc='upper right')
pyplot.show()
---------------------------------------------------------------------------
Error:
TypeError Traceback (most recent call last) <ipython-input-14-84f9c0bd2a25> in <module>() 12 pc=numpy.array(priceChanges['Perc Ch']) 13 plt.figure(figsize=(20,10)) ---> 14 pyplot.hist([pc,data],bins,label=["SignedPrice Changes as Percent of Previous Day","Normal Distribution"]) 15 SMALL_SIZE = 12 16 MEDIUM_SIZE = 14 C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\pyplot.py in hist(x, bins, range, density, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, normed, hold, data, **kwargs) 3023 histtype=histtype, align=align, orientation=orientation, 3024 rwidth=rwidth, log=log, color=color, label=label, -> 3025 stacked=stacked, normed=normed, data=data, **kwargs) 3026 finally: 3027 ax._hold = washold C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\__init__.py in inner(ax, *args, **kwargs) 1715 warnings.warn(msg % (label_namer, func.__name__), 1716 RuntimeWarning, stacklevel=2) -> 1717 return func(ax, *args, **kwargs) 1718 pre_doc = inner.__doc__ 1719 if pre_doc is None: C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in hist(***failed resolving arguments***) 6147 for xi in x: 6148 if len(xi) > 0: -> 6149 xmin = min(xmin, xi.min()) 6150 xmax = max(xmax, xi.max()) 6151 bin_range = (xmin, xmax) C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\_methods.py in _amin(a, axis, out, keepdims) 27 28 def _amin(a, axis=None, out=None, keepdims=False): ---> 29 return umr_minimum(a, axis, None, out, keepdims) 30 31 def _sum(a, axis=None, dtype=None, out=None, keepdims=False): TypeError: '<=' not supported between instances of 'float' and 'str'
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Describe repeating sequences in Dataframe and plot results PBRM 0 1,249 Dec-06-2021, 10:29 PM
Last Post: PBRM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020