0

I have a csv file where each row has a date yyyy-MM-dd and a count (e.g. 1, 2, 6).

2020-06-08,53
202-06-09,12

I read this into a dataframe as such and index on the date:

import pandas as pd

data_df = pd.read_csv('data.csv', header=0, names=['date', 'count'])
data_df['dt'] = pd.to_datetime(data_df['date'])
data_df = data_df.set_index('dt')
data_df.drop(['date'], axis=1, inplace=True)

I then create a dataframe for a date range:

date_rng = pd.date_range(start='1/1/2020', end='12/31/2020', freq='D')
df = pd.DataFrame(date_rng, columns=['date'])
df['dt'] = pd.to_datetime(df['date'])
df = df.set_index('dt')
df.drop(['date'], axis=1, inplace=True)
df['count'] = 0

Then I merged them:

df.update(data_df)

When I print df it looks correct - it contains the default data, and where present in the csv, contains the actual count from the corresponding csv row.

I then use the calmap module (https://pythonhosted.org/calmap/) to generate a heatmap over the year:

calmap.yearplot(df, year=2020, cmap='YlGn', daylabels='SMTWTFS', fig_kws=dict(figsize=(8, 4)))

I get this error:

ValueError: Shape of passed values is (1, 4), indices imply (366, 4)

I am missing something obvious. Most of the above code is lifted from somewhere.

Any help is appreciated. I am pretty new to pandas and I am working through some tutorials but so far nothing.

1 Answer 1

1

Can you try pass Series

calmap.yearplot(df['count'], year=2020, cmap='YlGn', daylabels='SMTWTFS', fig_kws=dict(figsize=(8, 4)))
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! Also, turns out calmap doesn't work with pandas 1.x so I switched to calplot and I am moving along. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.