Home > Net >  How to replace dates of 1 month to month in python?
How to replace dates of 1 month to month in python?

Time:12-06

enter image description here

Above is the image of the below dataframe with x-axis as date and y-axis as High enter image description here

what I want is for date between 06-09-21 to 31-09-21 it should replace it with sep 21 and likewise remaining dates with respected months in graph as right now the x-axis is not readable

I don't even know where to start with Below is the code that I used to draw/plot graph

    import pandas as pd
    from matplotlib import pyplot as plt
    df = pd.read_csv("Stock.csv")
    x1=df['High'].values.tolist()
    r=df['Date'].values.tolist()
    plt.plot(r, x1,color="green", label = "High")

CodePudding user response:

You can use enter image description here

Used input :

       Date         Open         High          Low        Close     AdjClose    Volume
0  06-09-21  1579.949951  1580.949951  1561.949951  1565.699951  1547.704712   3938448
1  07-09-21  1562.500000  1582.000000  1555.199951  1569.250000  1551.213989   3622748
2  08-09-21  1571.949951  1580.500000  1565.599976  1576.400024  1558.281860   3362040
3  09-09-21  1574.000000  1579.449951  1561.000000  1568.599976  1550.571411   4125474
4  13-09-21  1562.000000  1584.000000  1553.650024  1555.550049  1537.671509   4479582
5  30-08-22  1446.449951  1489.949951  1443.099976  1486.099976  1486.099976   5067700
6  01-09-22  1464.750000  1489.449951  1459.000000  1472.150024  1472.150024  11201568
7  02-09-22  1472.150024  1490.500000  1465.199951  1485.500000  1485.500000   6019043
8  05-09-22  1486.099976  1499.000000  1484.099976  1495.050049  1495.050049   6065966
9  06-09-22  1498.900024  1506.650024  1487.099976  1502.000000  1502.000000   4066957
  • Related