python - 熊猫比较列
问题描述
我正在处理波士顿 Hubway 系统的数据,我正在尝试计算早上开始的游乐设施数量和晚上开始的游乐设施数量。我要么得到一个错误,要么得到两个变量的输出 0,早上和晚上。这是我现在拥有的:
# Importing the data:
data = []
trip = open("ExData-trips.csv")
print(trip.readline().split(",")
for row in trip:
row = row.split(",")
row = [convert(x) for x in row]
data.append(row)
# Trying to divide the morning and evening times from the data above:
ride_times = [convert_date(row[3]) for row in data]
#pd.to_datetime(trip['start_date'].dt.hour
morning = 0
evening = 0
for time in trip:
if time.hour < 12:
morning += 1
else:
evening += 1
print(morning)
print(evening)
输出:0 和 0
我试过使用注释掉的行#pd.to_datetime(trip['start_date']).dt.hour
,但我得到一个错误:
TypeError:“_io.TextIOWrapper”对象不可下标
抱歉,如果格式关闭,我第一次在这个论坛上提问。让我知道是否需要任何其他信息。
解决方案
推荐阅读
- scala - 有没有办法使用 foldLeft 或任何其他列表方法对 scala 的函数进行排序?
- woocommerce - 在 WooCommerce 中添加另一个时删除一个特定的购物车项目
- inno-setup - Inno Setup - 带有复选框的多个安装目录
- unity3d - 在 Unity 中打开场景的外部链接?
- html - 自定义单选图标对齐问题,看起来像椭圆
- c# - 如何在Unity中提供一个圆形的球总是反弹到表面法线向量的方向?
- nativescript - 在 nativescript-pager 中动态添加项目会破坏视图顺序
- powershell - 从不同的远程计算机将文件从网络共享远程复制到本地驱动器路径
- python - 使用整数或布尔索引获取 numpy 数组视图
- javascript - ReactJS:创建鼠标悬停事件时出现重复