gpt4 book ai didi

python - 属性错误: 'DataFrame' object has no attribute 'compute'

转载 作者:行者123 更新时间:2023-12-01 08:17:25 24 4
gpt4 key购买 nike

我已经尝试过此代码,但显示属性错误。

from dask.base import compute
import dask.dataframe as dd
import pandas as pd
def dfWithTripTimes(df):
startTime=datetime.now()
duration=df[["tpep_pickup_datetime","tpep_dropoff_datetime"]].compute()
pickup_time=[timeToUnix(pkup) for pkuo in duration["tpep_pickup_datetime"].values]
dropoff_time=[timeToUnix(pkup) for pkuo in duration["tpep_dropoff_datetime"].values]
trip_Duration=(np.array(dropoff_time)-np.array(pickup_time))/float(60)
NewFrame=df[['passanger_count','trip_distance','pickup_longitude','pickup_latitude','dropoff_longitude','dropoff_latitude']]
NewFrame=df["trip_duration"]=trip_duration
NewFrame=df["pickup_time"]=pickup_time
NewFrame=df["speed"]=(NewFrame["trip_distance"]/NewFrame["Trip_Duration"])*60
print("Time taken for creation of dataframe is {}".format(datetime.now()-startTime))
return NewFrame
new_frame=dfWithTripTimes(data)

最佳答案

只有 Dask DataFrame 对象才有 .compute 方法。您得到的错误与您的数据框是 Pandas DataFrame 一致。如果您使用 Pandas,则无需调用 .compute()

关于python - 属性错误: 'DataFrame' object has no attribute 'compute' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54898315/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com