Plotting a trend graph in Python












-1















I have the following data in a DataFrame:



+----------------------+--------------+-------------------+
| Physician Profile Id | Program Year | Value Of Interest |
+----------------------+--------------+-------------------+
| 1004777 | 2013 | 83434288.00 |
| 1004777 | 2014 | 89237990.00 |
| 1004777 | 2015 | 96321258.00 |
| 1004777 | 2016 | 186993309.00 |
| 1004777 | 2017 | 205274459.00 |
| 1315076 | 2013 | 127454475.84 |
| 1315076 | 2014 | 156388338.20 |
| 1315076 | 2015 | 199733425.11 |
| 1315076 | 2016 | 242766959.37 |
+----------------------+--------------+-------------------+


I want to plot a trend graph with the Program year on the x-axis and Value of Interest on the y-axis and different lines for each Physician Profile ID. What is the best way to get this done?










share|improve this question























  • Plotly has a example of exactly this: plot.ly/python/linear-fits

    – Adam
    Nov 15 '18 at 20:12
















-1















I have the following data in a DataFrame:



+----------------------+--------------+-------------------+
| Physician Profile Id | Program Year | Value Of Interest |
+----------------------+--------------+-------------------+
| 1004777 | 2013 | 83434288.00 |
| 1004777 | 2014 | 89237990.00 |
| 1004777 | 2015 | 96321258.00 |
| 1004777 | 2016 | 186993309.00 |
| 1004777 | 2017 | 205274459.00 |
| 1315076 | 2013 | 127454475.84 |
| 1315076 | 2014 | 156388338.20 |
| 1315076 | 2015 | 199733425.11 |
| 1315076 | 2016 | 242766959.37 |
+----------------------+--------------+-------------------+


I want to plot a trend graph with the Program year on the x-axis and Value of Interest on the y-axis and different lines for each Physician Profile ID. What is the best way to get this done?










share|improve this question























  • Plotly has a example of exactly this: plot.ly/python/linear-fits

    – Adam
    Nov 15 '18 at 20:12














-1












-1








-1








I have the following data in a DataFrame:



+----------------------+--------------+-------------------+
| Physician Profile Id | Program Year | Value Of Interest |
+----------------------+--------------+-------------------+
| 1004777 | 2013 | 83434288.00 |
| 1004777 | 2014 | 89237990.00 |
| 1004777 | 2015 | 96321258.00 |
| 1004777 | 2016 | 186993309.00 |
| 1004777 | 2017 | 205274459.00 |
| 1315076 | 2013 | 127454475.84 |
| 1315076 | 2014 | 156388338.20 |
| 1315076 | 2015 | 199733425.11 |
| 1315076 | 2016 | 242766959.37 |
+----------------------+--------------+-------------------+


I want to plot a trend graph with the Program year on the x-axis and Value of Interest on the y-axis and different lines for each Physician Profile ID. What is the best way to get this done?










share|improve this question














I have the following data in a DataFrame:



+----------------------+--------------+-------------------+
| Physician Profile Id | Program Year | Value Of Interest |
+----------------------+--------------+-------------------+
| 1004777 | 2013 | 83434288.00 |
| 1004777 | 2014 | 89237990.00 |
| 1004777 | 2015 | 96321258.00 |
| 1004777 | 2016 | 186993309.00 |
| 1004777 | 2017 | 205274459.00 |
| 1315076 | 2013 | 127454475.84 |
| 1315076 | 2014 | 156388338.20 |
| 1315076 | 2015 | 199733425.11 |
| 1315076 | 2016 | 242766959.37 |
+----------------------+--------------+-------------------+


I want to plot a trend graph with the Program year on the x-axis and Value of Interest on the y-axis and different lines for each Physician Profile ID. What is the best way to get this done?







python python-3.x plot






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 19:49









Adarsh RaviAdarsh Ravi

6021028




6021028













  • Plotly has a example of exactly this: plot.ly/python/linear-fits

    – Adam
    Nov 15 '18 at 20:12



















  • Plotly has a example of exactly this: plot.ly/python/linear-fits

    – Adam
    Nov 15 '18 at 20:12

















Plotly has a example of exactly this: plot.ly/python/linear-fits

– Adam
Nov 15 '18 at 20:12





Plotly has a example of exactly this: plot.ly/python/linear-fits

– Adam
Nov 15 '18 at 20:12












2 Answers
2






active

oldest

votes


















1














Two routes I'd consider going with this:




  • Basic, fast, easy: matplotlib, which would look something like this:


    • install it, like pip install matplotlib

    • use it, like import matplotlib.pyplot as plt and this cheatsheet



  • Graphically compelling and you can drop your pandas dataframe right into it: Bokeh


I hope that helps you get started!






share|improve this answer































    1














    I tried a few things and was able to implement it:



    years = df["Program_Year"].unique()

    PhysicianIds = sorted(df["Physician_Profile_ID"].unique())

    pd.options.mode.chained_assignment = None

    for ID in PhysicianIds:
    df_filter = df[df["Physician_Profile_ID"] == ID]
    for year in years:
    found = False
    for index, row in df_filter.iterrows():
    if row["Program_Year"] == year:
    found = True
    break
    else:
    found = False
    if not found:
    df_filter.loc[index+1] = [ID, year, 0]
    VoI = list(df_filter["Value_of_Interest"])
    sns.lineplot(x=years, y=VoI, label=ID, linestyle='-')

    plt.ylabel("Value of Interest (in 100,000,000)")
    plt.xlabel("Year")
    plt.title("Top 10 Physicians")
    plt.legend(title="Physician Profile ID")
    plt.show()





    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%2f53326944%2fplotting-a-trend-graph-in-python%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









      1














      Two routes I'd consider going with this:




      • Basic, fast, easy: matplotlib, which would look something like this:


        • install it, like pip install matplotlib

        • use it, like import matplotlib.pyplot as plt and this cheatsheet



      • Graphically compelling and you can drop your pandas dataframe right into it: Bokeh


      I hope that helps you get started!






      share|improve this answer




























        1














        Two routes I'd consider going with this:




        • Basic, fast, easy: matplotlib, which would look something like this:


          • install it, like pip install matplotlib

          • use it, like import matplotlib.pyplot as plt and this cheatsheet



        • Graphically compelling and you can drop your pandas dataframe right into it: Bokeh


        I hope that helps you get started!






        share|improve this answer


























          1












          1








          1







          Two routes I'd consider going with this:




          • Basic, fast, easy: matplotlib, which would look something like this:


            • install it, like pip install matplotlib

            • use it, like import matplotlib.pyplot as plt and this cheatsheet



          • Graphically compelling and you can drop your pandas dataframe right into it: Bokeh


          I hope that helps you get started!






          share|improve this answer













          Two routes I'd consider going with this:




          • Basic, fast, easy: matplotlib, which would look something like this:


            • install it, like pip install matplotlib

            • use it, like import matplotlib.pyplot as plt and this cheatsheet



          • Graphically compelling and you can drop your pandas dataframe right into it: Bokeh


          I hope that helps you get started!







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 20:02









          TheLoneDerangerTheLoneDeranger

          9114




          9114

























              1














              I tried a few things and was able to implement it:



              years = df["Program_Year"].unique()

              PhysicianIds = sorted(df["Physician_Profile_ID"].unique())

              pd.options.mode.chained_assignment = None

              for ID in PhysicianIds:
              df_filter = df[df["Physician_Profile_ID"] == ID]
              for year in years:
              found = False
              for index, row in df_filter.iterrows():
              if row["Program_Year"] == year:
              found = True
              break
              else:
              found = False
              if not found:
              df_filter.loc[index+1] = [ID, year, 0]
              VoI = list(df_filter["Value_of_Interest"])
              sns.lineplot(x=years, y=VoI, label=ID, linestyle='-')

              plt.ylabel("Value of Interest (in 100,000,000)")
              plt.xlabel("Year")
              plt.title("Top 10 Physicians")
              plt.legend(title="Physician Profile ID")
              plt.show()





              share|improve this answer




























                1














                I tried a few things and was able to implement it:



                years = df["Program_Year"].unique()

                PhysicianIds = sorted(df["Physician_Profile_ID"].unique())

                pd.options.mode.chained_assignment = None

                for ID in PhysicianIds:
                df_filter = df[df["Physician_Profile_ID"] == ID]
                for year in years:
                found = False
                for index, row in df_filter.iterrows():
                if row["Program_Year"] == year:
                found = True
                break
                else:
                found = False
                if not found:
                df_filter.loc[index+1] = [ID, year, 0]
                VoI = list(df_filter["Value_of_Interest"])
                sns.lineplot(x=years, y=VoI, label=ID, linestyle='-')

                plt.ylabel("Value of Interest (in 100,000,000)")
                plt.xlabel("Year")
                plt.title("Top 10 Physicians")
                plt.legend(title="Physician Profile ID")
                plt.show()





                share|improve this answer


























                  1












                  1








                  1







                  I tried a few things and was able to implement it:



                  years = df["Program_Year"].unique()

                  PhysicianIds = sorted(df["Physician_Profile_ID"].unique())

                  pd.options.mode.chained_assignment = None

                  for ID in PhysicianIds:
                  df_filter = df[df["Physician_Profile_ID"] == ID]
                  for year in years:
                  found = False
                  for index, row in df_filter.iterrows():
                  if row["Program_Year"] == year:
                  found = True
                  break
                  else:
                  found = False
                  if not found:
                  df_filter.loc[index+1] = [ID, year, 0]
                  VoI = list(df_filter["Value_of_Interest"])
                  sns.lineplot(x=years, y=VoI, label=ID, linestyle='-')

                  plt.ylabel("Value of Interest (in 100,000,000)")
                  plt.xlabel("Year")
                  plt.title("Top 10 Physicians")
                  plt.legend(title="Physician Profile ID")
                  plt.show()





                  share|improve this answer













                  I tried a few things and was able to implement it:



                  years = df["Program_Year"].unique()

                  PhysicianIds = sorted(df["Physician_Profile_ID"].unique())

                  pd.options.mode.chained_assignment = None

                  for ID in PhysicianIds:
                  df_filter = df[df["Physician_Profile_ID"] == ID]
                  for year in years:
                  found = False
                  for index, row in df_filter.iterrows():
                  if row["Program_Year"] == year:
                  found = True
                  break
                  else:
                  found = False
                  if not found:
                  df_filter.loc[index+1] = [ID, year, 0]
                  VoI = list(df_filter["Value_of_Interest"])
                  sns.lineplot(x=years, y=VoI, label=ID, linestyle='-')

                  plt.ylabel("Value of Interest (in 100,000,000)")
                  plt.xlabel("Year")
                  plt.title("Top 10 Physicians")
                  plt.legend(title="Physician Profile ID")
                  plt.show()






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 16 '18 at 19:45









                  Adarsh RaviAdarsh Ravi

                  6021028




                  6021028






























                      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%2f53326944%2fplotting-a-trend-graph-in-python%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

                      Xamarin.iOS Cant Deploy on Iphone

                      Glorious Revolution

                      Dulmage-Mendelsohn matrix decomposition in Python