Skip to content
This repository was archived by the owner on Jun 12, 2019. It is now read-only.

Commit 8b470d2

Browse files
author
Tyler Hutcherson
authored
handle nans properly
1 parent bd1f52f commit 8b470d2

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

main.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,19 @@
4848
print("Validating a single record:", flush=True)
4949
print(gtrends_json['data'][0], flush=True)
5050

51-
# Convert to pandas df and handles string NaN's coming through data engine
51+
# Convert to pandas df
5252
gtrends = pd.DataFrame.from_records(gtrends_json['data'])\
53-
.pivot(index='date', values='interest', columns='keyword')\
54-
.replace({'NaN': None})\
55-
.fillna(method='pad')
53+
.pivot(index='date', values='interest', columns='keyword')
54+
55+
# Deal with potential nans
56+
for col in gtrends.columns:
57+
if 'NaN' in gtrends[col].values:
58+
gtrends[col].replace({'NaN': None}, inplace=True)
59+
else:
60+
continue
61+
62+
# If there are nans, fill using pad method
63+
gtrends.fillna(method='pad', inplace=True)
5664

5765
# Set proper date format
5866
gtrends.index = pd.to_datetime(gtrends.index)

0 commit comments

Comments
 (0)