青春须早为,岂能长少年。这篇文章主要讲述麻烦.apply()带'
int'
列的方法相关的知识,希望能为你提供帮助。
使用python中的'pandas'库来解决此代码的问题:
尝试将.apply()方法应用于'int'列。在我做def并尝试使用之前(if,else);
但是我收到以下错误:
TypeError: ("'>
=' not supported between instances of 'list' and 'int'", 'occurred at index A View to a Kill')
我试图将'Year'列从int64传递给'Str'。但它给了我几乎相同的错误。
bond = pd.read_csv('jamesbond.csv', index_col = 'Film')
bond.sort_index(inplace = True)
bond.head(3)def classic_modern(row):
year = [0]if year >
= 1990 :
return 'The movie is modern'
else :
return 'The movie is old one'
bond.apply(classic_modern , axis = 1)
答案此行初始化列表,其中包含1个值
0
:year = [0]
【麻烦.apply()带' int' 列的方法】接下来,将此列表与整数进行比较,从而导致错误:
if year >
= 1990:# if [0] >
= 1990
推荐阅读
- React Native,Android Studio,JDBC,MySql - 拒绝访问用户'root'@'ipaddress'
- Android(将片段和弹出窗口的点击事件中生成的变量传递给活动的方法)
- Android Clean Architecture中的登录流程
- 在Android 4.x中显示矢量图形
- android super.onBackPressed()计时
- Android P onStart在onActivityResult之前调用
- 如何在我的活动中设置Android铃声()
- 自动更改活动(Android中的横向和纵向模式)
- Android - 为什么人们反复引用内联静态上下文,而不是在Method()中传递一次()