How to plot two columns of a pandas data frame using points ?

How to plot two columns of a pandas data frame using points ?

Asked on December 22, 2018 in Pandas.
Add Comment


  • 2 Answer(s)

    The style can be specified using df.plot function:

    df.plot(x='col_name_1', y='col_name_2', style='o')
    

    The style can also be used as dict or list:

    import numpy as np
    import pandas as pd
     
    d = {'one' : np.random.rand(10),
    'two' : np.random.rand(10)}
     
    df = pd.DataFrame(d)
     
    df.plot(style=['o','rx'])
    

    Refer  matplotlib.pyplot.plot for various style formats.

    Answered on December 22, 2018.
    Add Comment

    We can use the matplotlib directly:

    import matplotlib.pyplot as plt
    plt.scatter(df['col_name_1'], df['col_name_2'])
    plt.show() # Depending on whether you use IPython or interactive mode, etc.
    

    The function df.col_name_1.values can be used to access a NumPy array.When the function datetime64 is used the result is an incorrent timestamp.

    Answered on December 22, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.