pandas_IO.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import pandas as pd
  2. df = pd.read_csv("ZILL-Z77006_C.csv") # reading in file
  3. df.set_index("Date", inplace=True) # setting index to date column
  4. print(df.head())
  5. # df.to_csv('ZILLOW_44106.csv')
  6. df = pd.read_csv(
  7. "ZILLOW_44106.csv", index_col=0
  8. ) # reading in file and setting index to the first column
  9. print(df.head())
  10. df.columns = ["Cleveland_HPI"] # House Price Index # renaming the columns
  11. # print(df.head())
  12. # df.to_csv('ZILLOW_44106_Rev3.csv', header = False)
  13. # reading in data, renaming columns, and setting index as first column
  14. df = pd.read_csv("ZILLOW_44106_Rev3.csv", names=["Date", "Cleveland_HPI"], index_col=0)
  15. # print(df.head())
  16. df.to_html("example.html") # to HTML (viewable in a web browser)
  17. df = pd.read_csv(
  18. "ZILLOW_44106_Rev3.csv", names=["Date", "Cleveland_HPI"]
  19. ) # reading in data and setting headers of columns
  20. print(df.head())
  21. df.rename(
  22. columns={"Cleveland_HPI": "Cleveland_44106_HPI"}, inplace=True
  23. ) # renaming a column
  24. df.rename(columns={"Cleveland_44106_HPI": "Cleveland_HPI"}, inplace=True)
  25. df.set_index("Date", inplace=True)
  26. print(df.head())