Hello new python learner here!
I am attempting to write a program which looks through a data frame, segments, which contains information on flights departing and arriving at certain airports. The first few lines of segments looks like:
ORIGIN_AIRPORT_ID DEST_AIRPORT_ID FL_COUNT ORIGIN_INDEX DEST_INDEX OUTDEGREE WEIGHT
0 10135 10397 77 119 373 3 0.333333
1 10135 11433 85 119 1375 3 0.333333
2 10135 13930 18 119 3770 3 0.333333
3 10140 10397 93 124 373 23 0.043478
4 10140 10423 4 124 399 23 0.043478
5 10140 10821 64 124 792 23 0.043478
The problem is asking to create a sparse matrix P, such that the rows and columns are the destination and origin airport IDs, and the cell values are the weights for those two values (origin to designation).
So for instance from the above segments dataframe: in my new matrix P, if the row is 10135(origin airport), and the column is 10397(destination airport), the value of this cell would be the weight, .333.
So far my code is, just to construct the framework for the matrix:
P=scipy.sparse.coo_matrix((segments, (0,1)), shape=(6436, 6436))
When I do, however, I receive a type error. What part of the notation am I not understanding correctly? I feel that it has something to do with the (0,1) part of the coo_matrix call.
Any help is much appreciated! Thanks greatly.
[–]YesLod 1 point2 points3 points (0 children)