got an error while opening and retrieving file from the link. I am attaching the screen short of my code
I have resolve the above issue but getting an error in the next steps. I am attaching the screen shot of my screen
Hi,
if you see the data, there are 2 columns namely date and dateymd
If you want to drop the dates, drop both columns
df_.drop(‘dateymd’,axis=1,inplace=True_)
Hi,
What’s wrong here:
import numpy as np
import pandas as pd
import seaborn as sns
import json
import urllib.request
#read the data
urllib.request.urlretrieve(“https://api.covid19india.org/states_daily.json”, “data1.json”)
with open(“data1.json”) as f:
js = json.load(f)
#normalize
df = pd.json_normalize(js[‘states_daily’])
df1 = df.copy()
df1.drop(columns=[‘un’, ‘dateymd’], inplace=True)
#set date time
df1[‘date’] = pd.to_datetime(df1[‘date’])
df1[‘ka’] = pd.to_numeric(df1[‘ka’])
df2 = pd.melt(df1, id_vars=‘date’, value_vars=list(df1.columns).remove(‘date’), var_name=‘state’, value_name=‘confirmed’)
#df2 = df2.sample(1000)
pd.to_numeric(df2[‘confirmed’])----------→ error?
#sns.lineplot(‘date’, ‘confirmed’, data=df2)
o/p:
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) pandas/_libs/lib.pyx in pandas._libs.lib.maybe_convert_numeric() ValueError: Unable to parse string “Confirmed” During handling of the above exception, another exception occurred: ValueError Traceback (most recent call last) <ipython-input-78-46658a68aba8> in <module>() ** 1** #df2 = df2.sample(1000) ----> 2 pd.to_numeric(df2[‘confirmed’]) ** 3** sns.lineplot(‘date’, ‘confirmed’, data=df2) /usr/local/lib/python3.7/dist-packages/pandas/core/tools/numeric.py in to_numeric(arg, errors, downcast) ** 151** try: ** 152** values = lib.maybe_convert_numeric( --> 153 values, set(), coerce_numeric=coerce_numeric ** 154** ) ** 155** except (ValueError, TypeError): pandas/_libs/lib.pyx in pandas._libs.lib.maybe_convert_numeric() ValueError: Unable to parse string “Confirmed” at position 10850
>>>>
print(df2.iloc\[10850\])
o/p:
date 2020-03-14 00:00:00
state status
confirmed Confirmed
Name: 10850, dtype: object
why it is corrupted?
>>>>>
df2.info()
---------------
<class ‘pandas.core.frame.DataFrame’>
RangeIndex: 13650 entries, 0 to 13649
Data columns (total 3 columns):
# Column Non-Null Count Dtype
— ------ -------------- -----
0 date 13650 non-null datetime64[ns]
1 state 13650 non-null object
2 confirmed 13650 non-null object
dtypes: datetime64[ns](1), object(2) memory usage: 320.0+ KB
let me know, i am doing some mistake may be, struck at week12 - class -lineplot - covid data,
oops got the ans:
df1.drop(‘status’, axis=1, inplace=True)
#df1 = df1.set_index(‘date’)
#df1[‘ka’] = pd.to_numeric(df1[‘ka’])
df1 = df1.apply(pd.to_numeric)
df1 = df1.rolling(7).mean()
df1.reset_index(inplace=True)
my categarical values not deleted, also not coverted to numeric. that’s caused the problem