Comments (2)
housing = pd.read_csv("City_Zhvi_AllHomes.csv")
housing.drop(housing.ix[:, '1996-04':'1999-12'], axis=1, inplace=True)
housing.drop(housing.ix[:, '2017-01':'2017-06'], axis=1, inplace=True)
housing.iloc[:,6:] = housing.iloc[:,6:].apply(pd.to_datetime, errors='coerce')
target = housing.iloc[:,6:].apply(pd.to_datetime, errors='coerce')
target = target.resample('Q', axis=1).mean()
I can't resample correctly...I wonder why...
from introduction-to-data-science-in-python.
I reached this far:
def convert_housing_data_to_quarters():
housing_df = pd.read_csv('City_Zhvi_AllHomes.csv')
State, Region = housing_df['State'], housing_df['RegionName']
StateName = []
for entry in State:
StateName.append(states[entry])
housing_df['StateName'] = StateName
housing_df = housing_df.set_index(['StateName', 'RegionName'])
housing_df = housing_df[housing_df.columns[-200:]]
recess_df = pd.ExcelFile('gdplev.xls').parse(skiprows=7).loc[212:].reset_index()
recess_df = recess_df[['Unnamed: 4', 'Unnamed: 5']]
recess_df = recess_df.rename(columns={'Unnamed: 4': 'Quarter', 'Unnamed: 5': 'GDP'})
recess_df['GDP'] = pd.to_numeric(recess_df['GDP'])
for quarter in recess_df['Quarter']:
count = 1
housing_df[quarter] = housing_df[count:count+2].mean(axis=1)
count += 3
housing_df['2016q3'] = housing_df[-2:-1].mean(axis=1)
housing_df = housing_df[housing_df.columns[-67:]]
return housing_df
I did get the desired dimensions, but this gives a lot of NaN values in the DataFrame. Any clues on how to solve that?
from introduction-to-data-science-in-python.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from introduction-to-data-science-in-python.