Answers for "pandas datetime column to int"

3

column dataframe to int

df[[column_name]].astype(int)
Posted by: Guest on April-21-2021
1

column of type int to date pandas

df['DataFrame Column'] = pd.to_datetime(df['DataFrame Column'], format=specify your format)

#Example
import pandas as pd

values = {'dates':  [20190902,20190913,20190921],
          'status': ['Opened','Opened','Closed']
          }

df = pd.DataFrame(values, columns = ['dates','status'])

df['dates'] = pd.to_datetime(df['dates'], format='%Y%m%d')

print (df)
print (df.dtypes)
Posted by: Guest on August-03-2021
2

convert a pandas column to int

# convert Series
my_series = pd.to_numeric(my_series)

# convert column "a" of a DataFrame
df["a"] = pd.to_numeric(df["a"])
Posted by: Guest on November-13-2020

Code answers related to "pandas datetime column to int"

Python Answers by Framework

Browse Popular Code Answers by Language