SoFunction
Updated on 2025-03-02

Subtract two columns of dates in dataframe and get a specific example of the number of months

Subtract two columns of dates in dataframe and get a specific example of the number of months

Updated: July 3, 2018 11:02:41 Author: peterchan88
Today, the editor will share with you an example of subtracting dates from two columns in the dataframe and obtaining specific months. It has good reference value and hopes it will be helpful to everyone. Let's take a look with the editor

As shown below:

df = ((6,4), index=pd.date_range('20130101', periods=6), columns=list('ABCD'))

 = pd.date_range('20160101', periods=6)
print (df)
df1 = ((6,4), index=pd.date_range('20130101', periods=6), columns=list('ABCD'))
 = pd.date_range('20170101', periods=6)
print (df1)
 = (pd.to_datetime() - pd.to_datetime()).dropna()
maps = (lambda x: x/np.timedelta64(1*60*60*24*30, 's'))
print (maps)

The above example of subtracting the dates of two columns in dataframe and obtaining specific months is all the content I share with you. I hope you can give you a reference and I hope you can support me more.

  • dataframe
  • date

Related Articles

  • Analysis of usage of() in Python

    This article mainly introduces the analysis of the usage of () in Python. The example code is introduced in this article in detail, which has certain reference learning value for everyone's study or work. Friends who need it, please learn with the editor below.
    2023-03-03
  • Advanced usage techniques for PyQt5 signals and slots in python GUI library graphical interface development Detailed usage methods and examples of decorator signals and slots

    This article mainly introduces the advanced usage skills of PyQt5 signals and slots in the python GUI library graphical interface development. Detailed usage methods and examples of decorator signals and slots. Friends who need it can refer to it.
    2020-03-03
  • Tutorial on graphic and text for building a python development environment under Win7 (install Python, pip, interpreter)

    This article mainly shares with you the graphic tutorial on building a python development environment under Win7. This article mainly introduces the detailed steps for installing Python, pip, and interpreter. Interested friends can refer to it.
    2016-05-05
  • python OpenCV realizes answer sheet recognition and paper judgment

    This article mainly introduces the python OpenCV answer sheet recognition and judgment papers in detail. The sample code in the article is introduced in detail and has certain reference value. Interested friends can refer to it.
    2021-06-06
  • Django one-to-many model and how to implement it in the front-end detailed explanation

    This article mainly introduces the one-to-many model of django and how to implement it in the front-end. The article introduces the example code in detail, which has certain reference learning value for everyone's learning or work. Friends who need it can refer to it.
    2019-07-07
  • Python implements the method of calculating network segments based on IP address and subnet mask

    This article mainly introduces the method of Python to calculate network segments based on IP address and subnet mask. It involves Python's string operation skills based on Linux platform. It has certain reference value. Friends who need it can refer to it.
    2015-07-07
  • pytorch tutorial network construction process notes

    This article mainly introduces the network construction process in the pytorch tutorial. The article includes detailed sample code flow. Friends in need can refer to it. I hope it can be helpful.
    2021-09-09
  • Use Python to automatically clean duplicate files in your computer, with only 10 lines of code (automatic script)

    This article mainly introduces the use of Python to automatically clean duplicate files in the computer. There are only 10 lines of code. This article introduces you very detailedly and has certain reference value for your study or work. Friends who need it can refer to it.
    2021-01-01
  • Interpreting the use of degrees() method in Python

    This article mainly introduces the use of the degree() method in Python, which is the basic knowledge in the introduction to Python. Friends who need it can refer to it.
    2015-05-05
  • Detailed explanation of the use and instructions of python ChainMap

    This article mainly introduces the detailed explanation of the use and explanation of python ChainMap. The example code is introduced in this article in detail, which has certain reference learning value for everyone's study or work. Friends who need it, please learn with the editor below.
    2019-06-06

Latest Comments