mmyjh86

[개인질문] DataFrame 변환 예제

Nov 21st, 2019
142
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from pandas import DataFrame
  2. import datetime
  3.  
  4. def convert_timestamp_to_datetime(x) :
  5.     return datetime.datetime.fromtimestamp(x/1000).strftime("%Y-%m-%d %H:%M")
  6.  
  7. jsonData = [
  8.     [1574337600000, 100, 200, 300, 400, 500],
  9.     [1574330400000, 110, 210, 220, 230, 330],
  10. ]
  11.  
  12. df = DataFrame(jsonData, columns=['Date', 'Open', 'Close', 'High', 'Low', 'Volume'])
  13. df['Date'] = df['Date'].apply(convert_timestamp_to_datetime)
  14. df = df.set_index('Date')
  15. print(df)
RAW Paste Data