首页 > 其他分享 >date or other data normalization general solution in pandas

date or other data normalization general solution in pandas

时间:2023-05-10 23:23:56浏览次数:39  
标签:__ dates 01 1980 df solution general other date

import pandas as pd import numpy as np
from sklearn.preprocessing import MinMaxScaler import time   # of course you can use basic pandas api doing this job, but I'd prefer general solution hereby def convert_to_timestamp(x):     """Convert date objects to integers"""     return time.mktime(x.to_datetime().timetuple())

def normalize(df):     """Normalize the DF using min/max"""     scaler = MinMaxScaler(feature_range=(-1, 1))     dates_scaled = scaler.fit_transform(df['dates'])     return dates_scaled     if __name__ == '__main__':     # Create a random series of dates     df = pd.DataFrame({         'dates':             ['1980-01-01', '1980-02-02', '1980-03-02', '1980-01-21',              '1981-01-21', '1991-02-21', '1991-03-23']     })
    # Convert to date objects     df['dates'] = pd.to_datetime(df['dates'])
    # Now df has date objects like you would, we convert to UNIX timestamps     df['dates'] = df['dates'].apply(convert_to_timestamp)
    # Call normalization function     df = normalize(df)

标签:__,dates,01,1980,df,solution,general,other,date
From: https://www.cnblogs.com/selfmade-Henderson/p/17389687.html

相关文章

  • Solution Set - “请背诵每条魔法的禁忌”
    目录0.「HAOI2018」「洛谷P4494」反色游戏1.「JSOI2010」「洛谷P6029」旅行2.「CTSC2017」「洛谷P3774」最长上升子序列⭐3.「CTSC2018」「洛谷P4566」青蕈领主⭐4.「CTSC2008」「洛谷P4528」图腾5.「SDOI2017」「洛谷P3779」龙与地下城6.「JSOI2018」「洛谷P4558......
  • Learning A Single Network for Scale-Arbitrary Super-Resolution
    LearningASingleNetworkforScale-ArbitrarySuper-Resolutionabstract现有的singleimageSR网络是为具有特定整数比例因子(例如,×2/3/4)的图像开发的,无法处理非整数和非对称SR。在本文中,作者建议从特定比例的网络中学习任意比例的图像SR网络。introduction由于上采样......
  • C++ Primer 5th Edition, Chapter 2, Solutions
    Exercise2.1QuestionsWhatarethedifferencesbetweenint,long,longlong,andshort?Betweenanunsignedandasignedtype?Betweenafloatandadouble?SolutionsThosetypeshavedifferentminimumsizesaslistedinTable2.1.Andadditionalru......
  • 07 A Glimpse of Industrial Solutions
    1.Anti-Aliasing1.1TemporelAnti-Aliasing(TAA)对于静止图像,每一帧的采样取像素内不同的区域,循环变化,下一帧复用上一帧的信息,考虑到递归,就会使得等效SSP变大。对于运动物体,使用motionvector来查找。如果出现遮挡等问题使得信息不可用,就采取相应的clamp等方法。1.2MS......
  • Solution Set before PKUSC
    JOISC2022Day2T1「チーム戦/TeamContest」首先优先考虑选择各项属性最大的那个。如果一只海狸同时霸占多项属性的最大值,那么这只海狸是不可能产生贡献的,将它删掉,然后对剩下的海狸继续进行如下的操作。如果没有就直接输出答案。如果所有海狸都删完了,则无解。时间复杂度\(O......
  • other初级语法
    1.other(限、adj)+n=others2.some....others 3.othertime no/any/everyother4.泛指其他人/事/物somestudents...;otherstudents...otherstudents=others.....5.特指剩余的全部20ofthestudents...   20 | 40  theothers6.one...theothe......
  • Solution Set - “让季节停止哽咽”
    目录0.「CTT2017」「洛谷P4004」Helloworld!1.「CTT2017」「洛谷P4006」小Y和二叉树2.「CTT2017」「洛谷P4226」避难所3.「AGC023F」01onTree4.「AGC024C」SequenceGrowingEasy5.「UR#1」「UOJ#21」缩进优化6.「JOISC2022」「LOJ#3694」一流团子师傅7.「JOISC......
  • Solution Set - “卷起击碎定论的漩涡”
    目录0.「CF1788F」XOR,Tree,andQueries1.「CF1815F」OHNO1(-2-3-4)2.「CF1787F」InverseTransformation3.「CF1797F」LiHuaandPath4.「CF1815B」SumGraph5.「AGC022C」RemainderGame6.「CTT2021」「洛谷P8986」基因编辑7.「CTT2021」「洛谷P8985」魔塔OL⭐......
  • Solution Set (春测集训中旬至省选集训)
    SolutionSetCF1767FTwoSubtrees首先,考虑询问\(u=v\)的情况,发现需要使用线段树合并,或者分块/莫队。问了一下,可以不用薯粉块啥的。但是9s啊9s,为啥啊为啥。考虑当前\(u\)最小众数是\(x\)(不妨设\(\maxu_x>\maxv_x\))。所以其出现次数是\(p=u_x+v_x\)。若......
  • Solution Set - APIO2015
    目录A.巴厘岛的雕塑B.雅加达的摩天楼C.巴邻旁之桥A巴厘岛的雕塑\(n\)个数分为若干组,组数不少于\(a\)且不多于\(b\)。最小化各组和的\(OR\)值。\(n\le2000\),\(1=a\leb\len\)或\(n\le100\),\(1\lea\leb\)。key:贪心,DP按位处理,从高到低依次尝试......