Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import numpy as np
- from dateutil import parser
- df = pd.read_csv('movies_complete.csv', parse_dates = ['release_date'])
- ######################################################
- all_ads_until_10_Oct['Date'] = [parser.parse(x) for x in all_ads_until_10_Oct['Date']]
- all_ads_until_10_Oct.head()
- pd.to_datetime(cars['model_year'], format= '%Y')
- cars['model_year'].astype('datetime64[ns]')
- #####################################################
- # convert year (string) into full date
- df_auto = df_auto.replace(r'^\s*$', np.nan, regex=True)
- df_auto = df_auto.dropna(subset = ["Year Manifacture"])
- df_auto['Year Manifacture'] = df_auto['Year Manifacture'].str.extract(r'(\d+)').astype(int)
- df_auto["Year Manifacture1"] = df_auto["Year Manifacture"].apply(lambda row: f'12/31/{row}')
- # and after that you can parse
- df_auto["Year Manifacture_new"] = [parser.parse(x) for x in df_auto["Year Manifacture_new"]]
- #####################################################
- # How to extract the months from date
- month_quantity_2017 = df_category_date_quantity.loc[mask1 & mask2].groupby(df_category_date_quantity.TransactionDate.dt.month).agg({'Quantity': 'sum'}).reset_index()
- month_quantity_2017
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement