pandas_IO.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  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('ZILLOW_44106.csv', index_col=0) # reading in file and setting index to the first column
  7. print(df.head())
  8. df.columns = ['Cleveland_HPI'] # House Price Index # renaming the columns
  9. # print(df.head())
  10. # df.to_csv('ZILLOW_44106_Rev3.csv', header = False)
  11. # reading in data, renaming columns, and setting index as first column
  12. df = pd.read_csv('ZILLOW_44106_Rev3.csv', names=['Date', 'Cleveland_HPI'], index_col=0)
  13. # print(df.head())
  14. df.to_html('example.html') # to HTML (viewable in a web browser)
  15. df = pd.read_csv('ZILLOW_44106_Rev3.csv', names=['Date', 'Cleveland_HPI']) # reading in data and setting headers of columns
  16. print(df.head())
  17. df.rename(columns={'Cleveland_HPI': 'Cleveland_44106_HPI'}, inplace = True) # renaming a column
  18. df.rename(columns={'Cleveland_44106_HPI' : 'Cleveland_HPI'}, inplace=True)
  19. df.set_index('Date', inplace = True)
  20. print(df.head())