如何使用此if条件创建新的数据帧?你知道吗
df = pd.DataFrame()
trips = pd.read_csv('trips.csv')
stops = pd.read_csv('stops.csv')
stop_times= pd.read_csv('stop_times.csv')
route_id = trips['route_id']
trip_id = trips['trip_id'] #deve coincidere con rip_id_stopTimes
direction_id = trips['direction_id'] # 0 -> andata, 1 -> ritorno
trip_id_stopTimes = stop_times['trip_id'] #deve coincidere con trip_id
stop_id = stop_times['stop_id'] #deve coincidere con stop_code
stop_code = stops['stop_code'] #deve coincidere con stop_id
stop_lat = stops['stop_lat']
stop_lon = stops['stop_lon']
stop_name = stops['stop_name']
#here is the problem
if str(trip_id_stopTimes) == str(trip_id) and str(stop_id) == str(stop_code):
df['NUMEROAMAT'] = route_id
df['IDVIAGGIO'] = trip_id
df['ANDATA/RITORNO'] = direction_id
df['IDVIAGGIO2'] = trip_id_stopTimes
df['IDFERMATA'] = stop_id
df['IDFERMATA2'] = stop_code
df['LATITUDINEFERMATA'] = stop_lat
df['LONGITUDINEFERMATA'] = stop_lon
df['NOMEFERMATA'] = stop_name
df.to_csv('Amat_finale.csv', index=False, encoding='utf-8')
我必须根据if条件创建一个新的数据帧。你知道吗
这能让你去吗?看起来你只是在测试真值。你知道吗
可以创建一系列事实并使用它创建数据帧。现在我已经仔细阅读了开头的部分,如果没有看到一些数据,也没有能力自己处理一下,就很难给出你想要的东西。你知道吗
上面给出的真值可以用来过滤值。我想到的一件事是,现在如何设置,它假设csv文件的长度和顺序相同,等等。您可能需要考虑使用.merge()来获取数据帧并将它们连接在一起。你知道吗
相关问题 更多 >
编程相关推荐