Geopandas Connect PointsLimiting floats to two decimal pointsPeak detection in a 2D arrayHow can I replace all the NaN values with Zero's in a column of a pandas dataframe“Large data” work flows using pandasHow to load mapinfo file into geopandasPass Series of colors/markers to matplotlib with geopandasExtracting geometry in geopandas (worldmap) into my dataframeConvert Points to Lines GeopandasMatplotlib map and subplot with different text at each data pointgeopandas cloropeth with two variables on map

Why is Collection not simply treated as Collection<?>

How can I prevent hyper evolved versions of regular creatures from wiping out their cousins?

prove that the matrix A is diagonalizable

Is it canonical bit space?

What reasons are there for a Capitalist to oppose a 100% inheritance tax?

Etiquette around loan refinance - decision is going to cost first broker a lot of money

What's the difference between 'rename' and 'mv'?

How much of data wrangling is a data scientist's job?

What mechanic is there to disable a threat instead of killing it?

In Romance of the Three Kingdoms why do people still use bamboo sticks when papers are already invented?

Is the Joker left-handed?

Why do I get two different answers for this counting problem?

AES: Why is it a good practice to use only the first 16bytes of a hash for encryption?

Does casting Light, or a similar spell, have any effect when the caster is swallowed by a monster?

Neighboring nodes in the network

Python: return float 1.0 as int 1 but float 1.5 as float 1.5

Assassin's bullet with mercury

Can I use a neutral wire from another outlet to repair a broken neutral?

Stopping power of mountain vs road bike

Why "Having chlorophyll without photosynthesis is actually very dangerous" and "like living with a bomb"?

Did Shadowfax go to Valinor?

Famous Pre Reformation Christian Pastors (Non Catholic and Non Orthodox)

How to take photos in burst mode, without vibration?

Today is the Center



Geopandas Connect Points


Limiting floats to two decimal pointsPeak detection in a 2D arrayHow can I replace all the NaN values with Zero's in a column of a pandas dataframe“Large data” work flows using pandasHow to load mapinfo file into geopandasPass Series of colors/markers to matplotlib with geopandasExtracting geometry in geopandas (worldmap) into my dataframeConvert Points to Lines GeopandasMatplotlib map and subplot with different text at each data pointgeopandas cloropeth with two variables on map






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am trying to create a basic origin/destination map of lines. My data has this structure:



ID lon_origin lat_origin lon_destination lat_destination
0 -116.284 43.617 -116.304 43.608
1 -116.291 43.610 -116.304 43.608


Any ideas on how to connect the origins & destinations? I have tried zipping them but I can't get geopandas to recognize two geometry columns at once.










share|improve this question






















  • What output do you expect?

    – giser_yugang
    Mar 8 at 3:31











  • Something like the .drawgreatcircle tool iterrated over each row in the dataframe. When I try that, I get TypeError: input must be an array, list, tuple or scalar.

    – bcparker21
    Mar 8 at 19:22












  • Solved the TypeError problem for a single row by calling .values after each column name. Now iterating is giving me the following: for index, row in df.iterrows(): m.drawgreatcircle(df['lon_orig'].values,df['lat_orig'].values,df['lon_dest'].values,df['lat_dest'].values, linewidth=2, color='orange') --------------------------------------------------------------------------- TypeError: only size-1 arrays can be converted to Python scalars

    – bcparker21
    Mar 8 at 19:46


















0















I am trying to create a basic origin/destination map of lines. My data has this structure:



ID lon_origin lat_origin lon_destination lat_destination
0 -116.284 43.617 -116.304 43.608
1 -116.291 43.610 -116.304 43.608


Any ideas on how to connect the origins & destinations? I have tried zipping them but I can't get geopandas to recognize two geometry columns at once.










share|improve this question






















  • What output do you expect?

    – giser_yugang
    Mar 8 at 3:31











  • Something like the .drawgreatcircle tool iterrated over each row in the dataframe. When I try that, I get TypeError: input must be an array, list, tuple or scalar.

    – bcparker21
    Mar 8 at 19:22












  • Solved the TypeError problem for a single row by calling .values after each column name. Now iterating is giving me the following: for index, row in df.iterrows(): m.drawgreatcircle(df['lon_orig'].values,df['lat_orig'].values,df['lon_dest'].values,df['lat_dest'].values, linewidth=2, color='orange') --------------------------------------------------------------------------- TypeError: only size-1 arrays can be converted to Python scalars

    – bcparker21
    Mar 8 at 19:46














0












0








0








I am trying to create a basic origin/destination map of lines. My data has this structure:



ID lon_origin lat_origin lon_destination lat_destination
0 -116.284 43.617 -116.304 43.608
1 -116.291 43.610 -116.304 43.608


Any ideas on how to connect the origins & destinations? I have tried zipping them but I can't get geopandas to recognize two geometry columns at once.










share|improve this question














I am trying to create a basic origin/destination map of lines. My data has this structure:



ID lon_origin lat_origin lon_destination lat_destination
0 -116.284 43.617 -116.304 43.608
1 -116.291 43.610 -116.304 43.608


Any ideas on how to connect the origins & destinations? I have tried zipping them but I can't get geopandas to recognize two geometry columns at once.







python pandas gis geopandas






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 7 at 23:58









bcparker21bcparker21

286




286












  • What output do you expect?

    – giser_yugang
    Mar 8 at 3:31











  • Something like the .drawgreatcircle tool iterrated over each row in the dataframe. When I try that, I get TypeError: input must be an array, list, tuple or scalar.

    – bcparker21
    Mar 8 at 19:22












  • Solved the TypeError problem for a single row by calling .values after each column name. Now iterating is giving me the following: for index, row in df.iterrows(): m.drawgreatcircle(df['lon_orig'].values,df['lat_orig'].values,df['lon_dest'].values,df['lat_dest'].values, linewidth=2, color='orange') --------------------------------------------------------------------------- TypeError: only size-1 arrays can be converted to Python scalars

    – bcparker21
    Mar 8 at 19:46


















  • What output do you expect?

    – giser_yugang
    Mar 8 at 3:31











  • Something like the .drawgreatcircle tool iterrated over each row in the dataframe. When I try that, I get TypeError: input must be an array, list, tuple or scalar.

    – bcparker21
    Mar 8 at 19:22












  • Solved the TypeError problem for a single row by calling .values after each column name. Now iterating is giving me the following: for index, row in df.iterrows(): m.drawgreatcircle(df['lon_orig'].values,df['lat_orig'].values,df['lon_dest'].values,df['lat_dest'].values, linewidth=2, color='orange') --------------------------------------------------------------------------- TypeError: only size-1 arrays can be converted to Python scalars

    – bcparker21
    Mar 8 at 19:46

















What output do you expect?

– giser_yugang
Mar 8 at 3:31





What output do you expect?

– giser_yugang
Mar 8 at 3:31













Something like the .drawgreatcircle tool iterrated over each row in the dataframe. When I try that, I get TypeError: input must be an array, list, tuple or scalar.

– bcparker21
Mar 8 at 19:22






Something like the .drawgreatcircle tool iterrated over each row in the dataframe. When I try that, I get TypeError: input must be an array, list, tuple or scalar.

– bcparker21
Mar 8 at 19:22














Solved the TypeError problem for a single row by calling .values after each column name. Now iterating is giving me the following: for index, row in df.iterrows(): m.drawgreatcircle(df['lon_orig'].values,df['lat_orig'].values,df['lon_dest'].values,df['lat_dest'].values, linewidth=2, color='orange') --------------------------------------------------------------------------- TypeError: only size-1 arrays can be converted to Python scalars

– bcparker21
Mar 8 at 19:46






Solved the TypeError problem for a single row by calling .values after each column name. Now iterating is giving me the following: for index, row in df.iterrows(): m.drawgreatcircle(df['lon_orig'].values,df['lat_orig'].values,df['lon_dest'].values,df['lat_dest'].values, linewidth=2, color='orange') --------------------------------------------------------------------------- TypeError: only size-1 arrays can be converted to Python scalars

– bcparker21
Mar 8 at 19:46













2 Answers
2






active

oldest

votes


















0














if you just want to calculate the distance, here is one solution :



from geopy.distance import lonlat, distance
data = """
id lon_origin lat_origin lon_destination lat_destination
0 -116.284 43.617 -116.304 43.608
1 -116.291 43.610 -116.304 43.608
"""
df = pd.read_csv(pd.compat.StringIO(data), sep='s+')
df['KM'] = df.apply(
(lambda row:distance(lonlat(row['lon_origin'], row['lat_origin']),
lonlat(row['lon_destination'], row['lat_destination'])).km), axis=1)

print(df)


output:



 id lon_origin lat_origin lon_destination lat_destination KM
0 0 -116.284 43.617 -116.304 43.608 1.89910
1 1 -116.291 43.610 -116.304 43.608 1.07277


if you want to use Miles, just change the metric:



df['MILES'] = df.apply(
(lambda row:distance(lonlat(row['lon_origin'], row['lat_origin']),
lonlat(row['lon_destination'], row['lat_destination'])).miles), axis=1)

id lon_origin lat_origin lon_destination lat_destination MILES
0 0 -116.284 43.617 -116.304 43.608 1.180046
1 1 -116.291 43.610 -116.304 43.608 0.666588





share|improve this answer






























    0














    I wound up forgoing the drawgreatcircle function because it wouldn't be very great or circular at the scale I was using. plt.plot did what I was after:
    Code & Output






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55054731%2fgeopandas-connect-points%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      if you just want to calculate the distance, here is one solution :



      from geopy.distance import lonlat, distance
      data = """
      id lon_origin lat_origin lon_destination lat_destination
      0 -116.284 43.617 -116.304 43.608
      1 -116.291 43.610 -116.304 43.608
      """
      df = pd.read_csv(pd.compat.StringIO(data), sep='s+')
      df['KM'] = df.apply(
      (lambda row:distance(lonlat(row['lon_origin'], row['lat_origin']),
      lonlat(row['lon_destination'], row['lat_destination'])).km), axis=1)

      print(df)


      output:



       id lon_origin lat_origin lon_destination lat_destination KM
      0 0 -116.284 43.617 -116.304 43.608 1.89910
      1 1 -116.291 43.610 -116.304 43.608 1.07277


      if you want to use Miles, just change the metric:



      df['MILES'] = df.apply(
      (lambda row:distance(lonlat(row['lon_origin'], row['lat_origin']),
      lonlat(row['lon_destination'], row['lat_destination'])).miles), axis=1)

      id lon_origin lat_origin lon_destination lat_destination MILES
      0 0 -116.284 43.617 -116.304 43.608 1.180046
      1 1 -116.291 43.610 -116.304 43.608 0.666588





      share|improve this answer



























        0














        if you just want to calculate the distance, here is one solution :



        from geopy.distance import lonlat, distance
        data = """
        id lon_origin lat_origin lon_destination lat_destination
        0 -116.284 43.617 -116.304 43.608
        1 -116.291 43.610 -116.304 43.608
        """
        df = pd.read_csv(pd.compat.StringIO(data), sep='s+')
        df['KM'] = df.apply(
        (lambda row:distance(lonlat(row['lon_origin'], row['lat_origin']),
        lonlat(row['lon_destination'], row['lat_destination'])).km), axis=1)

        print(df)


        output:



         id lon_origin lat_origin lon_destination lat_destination KM
        0 0 -116.284 43.617 -116.304 43.608 1.89910
        1 1 -116.291 43.610 -116.304 43.608 1.07277


        if you want to use Miles, just change the metric:



        df['MILES'] = df.apply(
        (lambda row:distance(lonlat(row['lon_origin'], row['lat_origin']),
        lonlat(row['lon_destination'], row['lat_destination'])).miles), axis=1)

        id lon_origin lat_origin lon_destination lat_destination MILES
        0 0 -116.284 43.617 -116.304 43.608 1.180046
        1 1 -116.291 43.610 -116.304 43.608 0.666588





        share|improve this answer

























          0












          0








          0







          if you just want to calculate the distance, here is one solution :



          from geopy.distance import lonlat, distance
          data = """
          id lon_origin lat_origin lon_destination lat_destination
          0 -116.284 43.617 -116.304 43.608
          1 -116.291 43.610 -116.304 43.608
          """
          df = pd.read_csv(pd.compat.StringIO(data), sep='s+')
          df['KM'] = df.apply(
          (lambda row:distance(lonlat(row['lon_origin'], row['lat_origin']),
          lonlat(row['lon_destination'], row['lat_destination'])).km), axis=1)

          print(df)


          output:



           id lon_origin lat_origin lon_destination lat_destination KM
          0 0 -116.284 43.617 -116.304 43.608 1.89910
          1 1 -116.291 43.610 -116.304 43.608 1.07277


          if you want to use Miles, just change the metric:



          df['MILES'] = df.apply(
          (lambda row:distance(lonlat(row['lon_origin'], row['lat_origin']),
          lonlat(row['lon_destination'], row['lat_destination'])).miles), axis=1)

          id lon_origin lat_origin lon_destination lat_destination MILES
          0 0 -116.284 43.617 -116.304 43.608 1.180046
          1 1 -116.291 43.610 -116.304 43.608 0.666588





          share|improve this answer













          if you just want to calculate the distance, here is one solution :



          from geopy.distance import lonlat, distance
          data = """
          id lon_origin lat_origin lon_destination lat_destination
          0 -116.284 43.617 -116.304 43.608
          1 -116.291 43.610 -116.304 43.608
          """
          df = pd.read_csv(pd.compat.StringIO(data), sep='s+')
          df['KM'] = df.apply(
          (lambda row:distance(lonlat(row['lon_origin'], row['lat_origin']),
          lonlat(row['lon_destination'], row['lat_destination'])).km), axis=1)

          print(df)


          output:



           id lon_origin lat_origin lon_destination lat_destination KM
          0 0 -116.284 43.617 -116.304 43.608 1.89910
          1 1 -116.291 43.610 -116.304 43.608 1.07277


          if you want to use Miles, just change the metric:



          df['MILES'] = df.apply(
          (lambda row:distance(lonlat(row['lon_origin'], row['lat_origin']),
          lonlat(row['lon_destination'], row['lat_destination'])).miles), axis=1)

          id lon_origin lat_origin lon_destination lat_destination MILES
          0 0 -116.284 43.617 -116.304 43.608 1.180046
          1 1 -116.291 43.610 -116.304 43.608 0.666588






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 8 at 8:07









          FrenchyFrenchy

          1,9882516




          1,9882516























              0














              I wound up forgoing the drawgreatcircle function because it wouldn't be very great or circular at the scale I was using. plt.plot did what I was after:
              Code & Output






              share|improve this answer



























                0














                I wound up forgoing the drawgreatcircle function because it wouldn't be very great or circular at the scale I was using. plt.plot did what I was after:
                Code & Output






                share|improve this answer

























                  0












                  0








                  0







                  I wound up forgoing the drawgreatcircle function because it wouldn't be very great or circular at the scale I was using. plt.plot did what I was after:
                  Code & Output






                  share|improve this answer













                  I wound up forgoing the drawgreatcircle function because it wouldn't be very great or circular at the scale I was using. plt.plot did what I was after:
                  Code & Output







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 8 at 20:08









                  bcparker21bcparker21

                  286




                  286



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55054731%2fgeopandas-connect-points%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

                      Алба-Юлія

                      Захаров Федір Захарович