私は次のようなユーザ定義関数を持っています: -TypeError:<class 'pandas.indexes.numeric.Int64Index'>でインデクサ[(2、)]><class 'tuple'>のスライスインデックスを作成できません>
def genre(option,option_type,*limit):
option_based = rank_data.loc[rank_data[option] == option_type]
top_option_based = option_based[:limit]
print(top_option_based)
top_option_based.to_csv('top_option_based.csv')
return(top_option_based))
私は
genre('genre','Crime',2)
としての機能を使用するとき、私は
としてエラーを取得しています。この imageを参照してください。別の答えで借入サンプルと
def genre(option,option_type,limit):
option_based = rank_data.loc[rank_data[option] == option_type]
top_option_based = option_based[:limit]
print(top_option_based)
top_option_based.to_csv('top_option_based.csv')
return(top_option_based)
それは完璧に動作します:
def genre(option,option_type,limit):
option_based = rank_data.loc[rank_data[option] == option_type]
top_option_based = option_based[:limit]
print(top_option_based)
top_option_based.to_csv('top_option_based.csv')
return(top_option_based)
print (genre('genre', 'Crime', 2))
genre
0 Crime
1 Crime
EDIT:
TypeError: cannot do slice indexing on <class 'pandas.indexes.numeric.Int64Index'> with these indexers [(2,)] of <class 'tuple'>".
あなたが '*'取り外す必要があるようです - 'あなたはまた、リターンラインに追加の閉じ括弧を持って – jezrael
ジャンル(オプション、option_type、制限を)'、おそらくタイプミス。ランクデータが存在しないなど機能が不足しているアイテムが存在するため、関数を実行したり定義したりすることはできません。試して、質問を完了させてください。そうでなければ、スニペットにはあまりにも多くの未知数がある場合、解決するのは難しいでしょう。 – grail
しかし、私は別のファイルでこの関数をインポートしているときに、 '' genre()は2つの位置引数をとりますが、3つは与えられたため、エラーが発生します。このエラーを回避するために、私は* –