[英]__init__() takes from 1 to 6 positional arguments but 11 were given
請幫助菜鳥解決問題。
我有2個列表,其中填充了str變量:
crops = ['Кук зер', 'Подсол', 'Пшен оз', 'Сах св', 'Соя', 'Ячм оз', 'Ячм яр']
clusters = ['Восток', 'Восток_2', 'Курск', 'Север', 'Центр', 'Юг',
'Юг_Краснодар', 'Юг_Ставрополь', 'Агросервис']
然后我想與他們建立一個簡單的熊貓數據集:
import pandas as pd
begrow = pd.DataFrame({'Crops': crops},
{clusters[0]: [2, 232, 503, 2442, 3858, '#Н/Д', 4706]},
{clusters[1]: [10, 259, 773, 2620, 3956, '#Н/Д', 4788]},
{clusters[2]: [13, 275, 900, 2754, 3961, '#Н/Д', 4843]},
{clusters[3]: [37, 313, 1446, 3085, 4171, '#Н/Д', 5039]},
{clusters[4]: [90, 322, 1647, 3207, 4285, '#Н/Д', 5090]},
{clusters[5]: [114, 360, 1810, 3293, 4351, '#Н/Д', 5155]},
{clusters[6]: [140, '#Н/Д', 2171, 3546, 4472, 4592, '#Н/Д']},
{clusters[7]: [187, 489, 2341, 3764, 4582, 4695, '#Н/Д']},
{clusters[8]: ['#Н/Д', 230, 490, 2421, 3811, '#Н/Д', 4704]})
print(begrow)
但是Spyder返回以下錯誤:
TypeError: __init__() takes from 1 to 6 positional arguments but 11 were given
如何解決?
錯誤__init__() takes from 1 to 6 positional arguments but 11 were given
意味着DataFrame構造函數最多接受6個不同的參數,並且將其喂入11。
每套{}
都會在Python中創建一個單獨的字典,這不是您想要的。 如果刪除除初始{
和結束}
之外的所有{}
,請按照以下步驟操作:
begrow = pd.DataFrame({'Crops': crops,
clusters[0]: [2, 232, 503, 2442, 3858, '#Н/Д', 4706],
clusters[1]: [10, 259, 773, 2620, 3956, '#Н/Д', 4788],
clusters[2]: [13, 275, 900, 2754, 3961, '#Н/Д', 4843],
clusters[3]: [37, 313, 1446, 3085, 4171, '#Н/Д', 5039],
clusters[4]: [90, 322, 1647, 3207, 4285, '#Н/Д', 5090],
clusters[5]: [114, 360, 1810, 3293, 4351, '#Н/Д', 5155],
clusters[6]: [140, '#Н/Д', 2171, 3546, 4472, 4592, '#Н/Д'],
clusters[7]: [187, 489, 2341, 3764, 4582, 4695, '#Н/Д'],
clusters[8]: ['#Н/Д', 230, 490, 2421, 3811, '#Н/Д', 4704]})
然后,它所有的數據組合到一個 dict
,輸出什么,我認為你正在尋找:
print(begrow)
runfile('/home/master/.config/spyder-py3/temp.py', wdir='/home/master/.config/spyder-py3')
Crops Восток Восток_2 Курск Север Центр Юг Юг_Краснодар Юг_Ставрополь Агросервис
0 Кук зер 2 10 13 37 90 114 140 187 #Н/Д
1 Подсол 232 259 275 313 322 360 #Н/Д 489 230
2 Пшен оз 503 773 900 1446 1647 1810 2171 2341 490
3 Сах св 2442 2620 2754 3085 3207 3293 3546 3764 2421
4 Соя 3858 3956 3961 4171 4285 4351 4472 4582 3811
5 Ячм оз #Н/Д #Н/Д #Н/Д #Н/Д #Н/Д #Н/Д 4592 4695 #Н/Д
6 Ячм яр 4706 4788 4843 5039 5090 5155 #Н/Д #Н/Д 4704
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.