tristantao / leada_python_workshop

3 stars 1 forks source link

Getting Error probably related to date format :( #1

Open franz101 opened 8 years ago

franz101 commented 8 years ago

Traceback (most recent call last): File "src.py", line 52, in unstacked_from, unstacked_to, unstacked_total = my_lp.extract_top_friends_series(top_friends_from_key, top_friends_to_key) File "/Users/franz/Downloads/leada_python_workshop-master/leada_parser.py", line 46, in extract_top_friends_series self.from_df = append_to_df(self.from_df, [date, friend_name])#, index=from_idex) File "/Users/franz/Downloads/leada_python_workshop-master/leada_util.py", line 31, in append_to_df df = pd.concat([df,temp_df]) File "//anaconda/lib/python2.7/site-packages/pandas/tools/merge.py", line 846, in concat return op.get_result() File "//anaconda/lib/python2.7/site-packages/pandas/tools/merge.py", line 1038, in get_result copy=self.copy) File "//anaconda/lib/python2.7/site-packages/pandas/core/internals.py", line 4545, in concatenate_block_managers for placement, join_units in concat_plan] File "//anaconda/lib/python2.7/site-packages/pandas/core/internals.py", line 4642, in concatenate_join_units for ju in join_units] File "//anaconda/lib/python2.7/site-packages/pandas/core/internals.py", line 4915, in get_reindexed_values missing_arr = np.empty(self.shape, dtype=empty_dtype) TypeError: data type not understood

micahcarroll commented 7 years ago

Around line 31 the code should be changed from the following:

temp_df = pd.DataFrame([entry], columns=['date', 'name'])
df = pd.concat([df,temp_df])
last_index = len(df)
return df

to the following:

if df.empty:
    df = temp_df
else:
    df = pd.concat([df,temp_df])

last_index = len(df)
return df

The problem as far as I can tell was that pandas concat method does not expect a combination of empty and full (with-values) DataFrames.