Advertisement
s_hossain18

CSV File Read Pandas

Aug 9th, 2022 (edited)
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. # https://www.rasgoml.com/feature-engineering-tutorials/how-to-create-time-series-features-with-tsfresh
  2.  
  3. import pandas as pd
  4. import tsfresh
  5. from urllib.request import urlopen
  6. from io import BytesIO
  7. from zipfile import ZipFile
  8.  
  9.  
  10. url = "https://archive.ics.uci.edu/ml/machine-learning-databases/00501/PRSA2017_Data_20130301-20170228.zip"
  11. r = urlopen(url)
  12. zf = ZipFile(BytesIO(r.read()))
  13.  
  14. df = pd.DataFrame()
  15. for file in zf.infolist():
  16.     if file.filename.endswith('.csv'):
  17.         df = df.append(pd.read_csv(zf.open(file)))
  18.  
  19. df['timestamp'] = pd.to_datetime(df[["year", "month", "day", "hour"]])
  20. df.drop(columns=['No'], inplace=True)
  21. df.sort_values(by=['timestamp', 'station']).head(10)
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement