Skip to content

TypeError: can't multiply sequence by non-int of type 'float' #26452

@pengguanjun

Description

@pengguanjun

Code Sample, a copy-pastable example if possible

# Your code here
import numpy as np  
import pandas as pd
import matplotlib.pyplot as plt  
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
plt.rcParams['font.sans-serif'] = ['KaiTi']
plt.rcParams['font.serif'] = ['KaiTi']
# plt.rcParams['axes.unicode_minus'] = False # 解决保存图像是负号'-'显示为方块的问题,或者转换负号为字符串
import seaborn as sns  
sns.set_style("darkgrid",{"font.sans-serif":['KaiTi', 'Arial']})   #这是方便seaborn绘图得时候得字体设置

sns.set( palette="muted", color_codes=True)  

d = pd.read_csv('C:/Users/MaiBenBen/Desktop/nicetable/03170809.csv',sep=';', encoding='gbk')
f, ax = plt.subplots( figsize=(7,7))
plt.title('Histgram of Rock Fragmentation', fontsize=22)

print(d)
print(d.columns)
print(type(d))
y = d.loc[:,'Diameter']
#y = list(d.loc[:,'Diameter'])
print(type(y))
print(y)

#fig,axes=plt.subplots(1,2)
#sns.distplot(x,norm_hist=True,kde=False,ax=axes[0]) #左图
#sns.distplot(x,kde=False,ax=axes[1]) #右图
sns.distplot(y,kde=False,color="r")  
#sns.distplot(d.loc[:,'Diameter'],kde=False,color="r")  

print('---------------------------')
#group_labels = ['0', '10', '20','30','40','50','60', '70','80','90','100']
#ax.set_yticklabels(group_labels,#设置刻度对应的标签
#                   rotation=0, fontsize='small')#rotation选项设定x刻度标签倾斜30度。

plt.xlabel('size (cm)')
plt.ylabel('quantity of fragmentations')  #只有最后一个图有改变

fig = ax.get_figure()
fig.savefig('c-1.png', dpi=100, bbox_inches='tight')
plt.show() 

Problem description

[this should explain why the current behaviour is a problem and why the expected output is a better solution.]
图片

Note: We receive a lot of issues on our GitHub tracker, so it is very possible that your issue has been posted before. Please check first before submitting so that we do not have to handle and close duplicates!

Note: Many problems can be resolved by simply upgrading pandas to the latest version. Before submitting, please check if that solution works for you. If possible, you may want to check if master addresses this issue, but that is not necessary.

For documentation-related issues, you can check the latest versions of the docs on master here:

https://pandas-docs.github.io/pandas-docs-travis/

If the issue has not been resolved there, go ahead and file it in the issue tracker.

Expected Output

 Unnamed: 0   ID  Center-X  Center-Y   Area  Perimeter  Min-Y  Min-X  Max-Y  Max-X  (pix)Diameter  ConvexArea  Holes  FilledArea  Solidity  Major  Minor  Ori       Diameter

0 0 0 6.8 17.0 359 95.5 2 2 40 17 21.4 417 0 359 0.86 41.7 12.7 1.4 1.681.916.933
1 1 1 106.2 73.5 25099 924.9 2 2 165 270 178.8 30361 0 25099 0.83 242.4 150.6 0.3 1.405.265.176
2 2 2 233.1 5.8 232 75.4 2 217 12 251 17.2 255 0 232 0.91 33.8 9.0 -0.1 1.351.821.086
3 3 3 269.6 2.6 5 3.0 2 269 5 272 2.5 6 0 5 0.83 4.0 2.1 0.8 196.485.623
4 4 4 296.0 2.0 3 1.0 2 295 3 298 2.0 3 0 3 1.00 3.3 0.0 0.0 1.571.884.984
5 5 5 341.2 52.1 10897 617.2 2 226 97 455 117.8 13789 0 10897 0.79 203.8 87.4 -0.1 9.258.402.556
6 6 6 595.9 31.1 11264 1027.4 2 421 100 725 119.8 19139 0 11264 0.59 268.8 90.7 0.0 9.415.591.054
7 7 7 743.6 26.6 1199 156.6 2 725 54 762 39.1 1384 0 1199 0.87 57.1 29.2 -1.3 3.073.035.144
8 8 8 843.6 42.0 7722 612.8 2 765 90 940 99.2 10442 0 7722 0.74 175.6 65.5 -0.3 7.796.549.521
9 9 9 892.5 3.0 6 6.0 2 892 5 894 2.8 6 0 6 1.00 3.3 2.0 -1.6 2.200.638.978
10 10 10 907.5 2.0 2 0.0 2 907 3 909 1.6 2 0 2 1.00 2.0 0.0 0.0 1.257.507.987
11 11 11 927.1 18.4 147 64.0 2 923 32 933 13.7 182 0 147 0.81 28.5 7.6 -1.3 1.076.741.214
12 12 12 1179.1 12.2 544 138.3 2 1162 25 1207 26.3 759 0 544 0.72 42.4 22.8 0.1 2.067.028.754
13 13 13 1273.9 38.7 9789 475.7 2 1193 88 1343 111.6 10616 0 9789 0.92 151.7 85.6 -0.1 8.771.118.211
14 14 14 1384.0 3.0 3 1.0 2 1384 5 1385 2.0 3 0 3 1.00 3.3 0.0 -1.6 1.571.884.984
15 15 15 257.0 7.0 1 0.0 7 257 8 258 1.1 1 0 1 1.00 0.0 0.0 0.8 0.864536741
16 16 16 171.0 13.0 3 1.0 13 170 14 173 2.0 3 0 3 1.00 3.3 0.0 0.0 1.571.884.984
17 17 17 281.0 13.5 18 18.0 13 277 15 286 4.8 18 0 18 1.00 10.3 2.0 0.0 3.772.523.962
18 18 18 1115.7 25.5 480 95.9 14 1101 39 1137 24.7 537 0 480 0.89 34.8 18.6 0.4 1.941.277.955
19 19 19 286.0 15.0 1 0.0 15 286 16 287 1.1 1 0 1 1.00 0.0 0.0 0.8 0.864536741
20 20 20 1010.9 38.3 910 179.5 15 980 64 1044 34.0 1092 0 910 0.83 77.0 16.9 -0.7 2.672.204.473
21 21 21 913.6 20.0 20 14.6 17 912 23 916 5.0 21 0 20 0.95 6.2 4.2 1.3 392.971.246
22 22 22 876.9 19.1 8 7.4 18 876 21 879 3.2 8 0 8 1.00 3.5 2.7 -0.8 2.515.015.974
23 23 23 1349.0 19.0 1 0.0 19 1349 20 1350 1.1 1 0 1 1.00 0.0 0.0 0.8 0.864536741
24 24 24 725.0 20.0 1 0.0 20 725 21 726 1.1 1 0 1 1.00 0.0 0.0 0.8 0.864536741
25 25 25 1360.3 29.5 295 89.5 20 1350 41 1382 19.4 387 0 295 0.76 28.3 16.8 0.3 1.524.728.435
26 26 26 879.0 21.0 1 0.0 21 879 22 880 1.1 1 0 1 1.00 0.0 0.0 0.8 0.864536741
27 27 27 219.2 25.1 31 24.1 23 214 30 224 6.3 44 0 31 0.70 10.2 5.7 -0.2 49.514.377
28 28 28 891.8 23.4 5 5.2 23 891 25 894 2.5 5 0 5 1.00 3.1 1.8 0.3 196.485.623
29 29 29 905.7 25.8 53 26.4 23 902 31 910 8.2 56 0 53 0.95 9.2 7.6 -0.3 6.444.728.435
.. ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
449 449 449 1295.5 876.0 2 0.0 876 1295 877 1297 1.6 2 0 2 1.00 2.0 0.0 0.0 1.257.507.987
450 450 450 685.4 905.9 1543 192.8 877 651 924 714 44.3 1845 0 1543 0.84 57.4 40.7 0.7 348.172.524
451 451 451 378.7 880.4 7 7.2 880 377 882 381 3.0 7 0 7 1.00 4.2 1.9 -0.1 2.357.827.476
452 452 452 312.5 883.0 2 0.0 883 312 884 314 1.6 2 0 2 1.00 2.0 0.0 0.0 1.257.507.987
453 453 453 1341.1 902.6 249 82.9 885 1334 919 1349 17.8 332 0 249 0.75 33.1 11.6 -1.4 1.398.977.636
454 454 454 666.0 888.0 1 0.0 888 666 889 667 1.1 1 0 1 1.00 0.0 0.0 0.8 0.864536741
455 455 455 750.0 888.5 2 0.0 888 750 890 751 1.6 2 0 2 1.00 2.0 0.0 -1.6 1.257.507.987
456 456 456 729.5 891.0 2 0.0 891 729 892 731 1.6 2 0 2 1.00 2.0 0.0 0.0 1.257.507.987
457 457 457 997.2 895.6 8 7.4 894 996 898 1000 3.2 10 0 8 0.80 5.5 2.1 -0.6 2.515.015.974
458 458 458 1300.5 895.5 11 9.2 894 1299 900 1303 3.7 15 0 11 0.73 6.8 3.4 -1.4 290.798.722
459 459 459 586.8 900.4 38 24.7 897 584 906 592 7.0 47 0 38 0.81 8.5 6.8 -1.5 5.501.597.444
460 460 460 406.3 904.6 24 17.1 901 402 909 412 5.5 40 0 24 0.60 9.8 4.8 -0.7 4.322.683.706
461 461 461 449.3 908.0 73 36.9 901 444 914 455 9.6 92 0 73 0.79 12.3 9.2 -1.1 7.545.047.923
462 462 462 1204.0 902.0 1 0.0 902 1204 903 1205 1.1 1 0 1 1.00 0.0 0.0 0.8 0.864536741
463 463 463 1206.5 903.0 2 0.0 903 1206 904 1208 1.6 2 0 2 1.00 2.0 0.0 0.0 1.257.507.987
464 464 464 10.3 915.4 307 75.8 904 2 924 26 19.8 333 0 307 0.92 27.0 16.4 -0.7 1.556.166.134
465 465 465 1383.0 904.0 1 0.0 904 1383 905 1384 1.1 1 0 1 1.00 0.0 0.0 0.8 0.864536741
466 466 466 1212.0 905.5 4 4.4 905 1211 907 1214 2.3 4 0 4 1.00 3.2 1.2 -0.6 1.807.667.732
467 467 467 1384.0 905.0 1 0.0 905 1384 906 1385 1.1 1 0 1 1.00 0.0 0.0 0.8 0.864536741
468 468 468 580.1 917.9 580 145.6 907 551 924 614 27.2 755 0 580 0.77 61.9 15.1 -0.1 2.137.763.578
469 469 469 1381.0 916.6 63 42.0 909 1375 924 1385 9.0 107 0 63 0.59 18.0 8.4 -1.1 7.073.482.428
470 470 470 403.0 913.0 5 3.0 913 401 914 406 2.5 5 0 5 1.00 5.7 0.0 0.0 196.485.623
471 471 471 421.6 919.1 71 50.3 913 412 924 430 9.5 138 0 71 0.51 23.1 8.7 -0.3 7.466.453.674
472 472 472 714.0 920.1 35 23.9 915 710 924 718 6.7 37 0 35 0.95 11.1 4.7 0.9 5.265.814.696
473 473 473 1373.0 917.0 1 0.0 917 1373 918 1374 1.1 1 0 1 1.00 0.0 0.0 0.8 0.864536741
474 474 474 439.2 919.8 26 17.4 918 437 923 443 5.8 27 0 26 0.96 6.8 5.0 0.5 4.558.466.454
475 475 475 483.0 918.0 1 0.0 918 483 919 484 1.1 1 0 1 1.00 0.0 0.0 0.8 0.864536741
476 476 476 481.5 919.0 2 0.0 919 481 920 483 1.6 2 0 2 1.00 2.0 0.0 0.0 1.257.507.987
477 477 477 1298.5 923.0 16 14.0 923 1291 924 1307 4.5 16 0 16 1.00 18.4 0.0 0.0 3.536.741.214
478 478 478 1321.0 923.0 3 1.0 923 1320 924 1323 2.0 3 0 3 1.00 3.3 0.0 0.0 1.571.884.984

[479 rows x 19 columns]
Index(['Unnamed: 0', 'ID', 'Center-X', 'Center-Y', 'Area', 'Perimeter',
'Min-Y', 'Min-X', 'Max-Y', 'Max-X', '(pix)Diameter', 'ConvexArea',
'Holes', 'FilledArea', 'Solidity', 'Major', 'Minor', 'Ori', 'Diameter'],
dtype='object')
<class 'pandas.core.frame.DataFrame'>
<class 'pandas.core.series.Series'>
0 1.681.916.933
1 1.405.265.176
2 1.351.821.086
3 196.485.623
4 1.571.884.984
5 9.258.402.556
6 9.415.591.054
7 3.073.035.144
8 7.796.549.521
9 2.200.638.978
10 1.257.507.987
11 1.076.741.214
12 2.067.028.754
13 8.771.118.211
14 1.571.884.984
15 0.864536741
16 1.571.884.984
17 3.772.523.962
18 1.941.277.955
19 0.864536741
20 2.672.204.473
21 392.971.246
22 2.515.015.974
23 0.864536741
24 0.864536741
25 1.524.728.435
26 0.864536741
27 49.514.377
28 196.485.623
29 6.444.728.435
...
449 1.257.507.987
450 348.172.524
451 2.357.827.476
452 1.257.507.987
453 1.398.977.636
454 0.864536741
455 1.257.507.987
456 1.257.507.987
457 2.515.015.974
458 290.798.722
459 5.501.597.444
460 4.322.683.706
461 7.545.047.923
462 0.864536741
463 1.257.507.987
464 1.556.166.134
465 0.864536741
466 1.807.667.732
467 0.864536741
468 2.137.763.578
469 7.073.482.428
470 196.485.623
471 7.466.453.674
472 5.265.814.696
473 0.864536741
474 4.558.466.454
475 0.864536741
476 1.257.507.987
477 3.536.741.214
478 1.571.884.984
Name: Diameter, Length: 479, dtype: object
C:\Users\MaiBenBen\Python36\lib\site-packages\scipy\stats\stats.py:1713: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use arr[tuple(seq)] instead of arr[seq]. In the future this will be interpreted as an array index, arr[np.array(seq)], which will result either in an error or a different result.
return np.add.reduce(sorted[indexer] * weights, axis=axis) / sumval
Traceback (most recent call last):
File "c:\Users\MaiBenBen.vscode\extensions\ms-python.python-2019.4.12954\pythonFiles\ptvsd_launcher.py", line 43, in
main(ptvsdArgs)
File "c:\Users\MaiBenBen.vscode\extensions\ms-python.python-2019.4.12954\pythonFiles\lib\python\ptvsd_main_.py", line 410, in main
run()
File "c:\Users\MaiBenBen.vscode\extensions\ms-python.python-2019.4.12954\pythonFiles\lib\python\ptvsd_main_.py", line 291, in run_file
runpy.run_path(target, run_name='main')
File "C:\Users\MaiBenBen\Python36\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\Users\MaiBenBen\Python36\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\MaiBenBen\Python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\Users\MaiBenBen\Desktop\nicetable\HIST.py", line 28, in
sns.distplot(y,kde=False,color="r")
File "C:\Users\MaiBenBen\Python36\lib\site-packages\seaborn\distributions.py", line 215, in distplot
bins = min(_freedman_diaconis_bins(a), 50)
File "C:\Users\MaiBenBen\Python36\lib\site-packages\seaborn\distributions.py", line 34, in _freedman_diaconis_bins
h = 2 * iqr(a) / (len(a) ** (1 / 3))
File "C:\Users\MaiBenBen\Python36\lib\site-packages\seaborn\utils.py", line 366, in iqr
q1 = stats.scoreatpercentile(a, 25)
File "C:\Users\MaiBenBen\Python36\lib\site-packages\scipy\stats\stats.py", line 1670, in scoreatpercentile
return _compute_qth_percentile(sorted, per, interpolation_method, axis)
File "C:\Users\MaiBenBen\Python36\lib\site-packages\scipy\stats\stats.py", line 1713, in _compute_qth_percentile
return np.add.reduce(sorted[indexer] * weights, axis=axis) / sumval
TypeError: can't multiply sequence by non-int of type 'float'

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]
commit: None
python: 3.6.4.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 60 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.24.2
pytest: None
pip: 19.1.1
setuptools: 28.8.0
Cython: None
numpy: 1.16.3
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 6.5.0
sphinx: None
patsy: None
dateutil: 2.7.2
pytz: 2018.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.2.2
openpyxl: 2.5.4
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.1.2
lxml.etree: 4.2.1
bs4: None
html5lib: 1.0.1
sqlalchemy: 1.2.8
pymysql: 0.9.0
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: 0.7.0
gcsfs: None

        pd.version
        '0.24.2'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs InfoClarification about behavior needed to assess issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions