Creating pandas dataframe with datetime index and random values in column

前端 未结 3 660
抹茶落季
抹茶落季 2020-12-28 09:03

How do I create a pandas dataframe with datetime as index, and random values for a column. Currently, I have this:

from datetime import datetime, timedelta

         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-28 10:01

    import pandas as pd
    import numpy as np
    
    df = pd.DataFrame(np.random.randint(0,30,size=10),
                      columns=["Random"],
                      index=pd.date_range("20180101", periods=10))
    

提交回复
热议问题