-
Notifications
You must be signed in to change notification settings - Fork 18.4k
[SOLUTION] - Pandas + Python - Pulls daily data for Recoveries @worldmeters.info and transforms in @JHU standards #1642
Comments
noiceeeeeeeeeeeeeeeeeeee |
it seems you're missing Also line 110: I'm now correctly getting worldometer_recovered_2020_03_26.csv correctly in my folder P.S. I also had to pip install lxml |
@ablanch5 sorry, I forgot a few imports. I modified the code above, can you try now? |
@ablanch5 the dashes are to avoid padding in the date e.g. NOT "03/25/2020" but instead "3/25/2020" so I used the dashes to be compliant with JHU... Maybe your python version does not support that format? |
I'm using python 3.7.6. When I look at the csv file I'm getting 3/25/2020 like you wanted. Could it be a Linux/Windows thing? I don't know |
@ablanch5 I don't know. I use Linux. Glad it worked, anyway! Enjoy :) |
I think its a windows/linux thing: Nice work! |
Something like this would fix the date format issue:
|
@efra-mx have you tested it? If you have and you sure it works, I'll update the code snippet. Otherwise if not tested, let's just leave your comment here for inspiration for future readers. In the meanwhile I've updated the code because since today if you don't "pretend to be a browser" they give you a 403 error. Now the problem is fixed (I don't get why they try to protect a public HTML table on a public page, in times of pandemic... Nevertheless, for now it still works with the updated code) |
@r-lomba I don't have a windows machine myself. Good job by the way. |
I wanted to share a refactored version of the code done by @r-lomba. r = CovidReader() I hope you find it helpful
|
Brilliant, @efra-mx !! Thanks a lot for this :) |
Something like this would help :
df.groupby(['country/other']).sum()
…On Thu, 9 Apr 2020, 16:08 Marco Cheung ***@***.***> wrote:
Since 'Diamond Princess' cases are seperated from 'Japan' in Worldometers
table, may I know how to group Diamond Princess cases into Japan? Thanks
[image: image]
<https://user-images.githubusercontent.com/29329279/78903825-46dce000-7aae-11ea-96cd-b7719671330e.png>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1642 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB5C7WZXYBRP4ZKESMNKVZDRLXJFZANCNFSM4LUO3NVQ>
.
|
@efra-mx Thanks for follow-up. Can group them using this function after converting object data fields into float. However, the original column 'Continent' is missing after grouping. May I know how to add back into dataframe? Thanks! |
the easiest way would be, if you also use the version of my script:
import worldmeter_stats as wms
reader = wms.CovidReader()
reader.fetch()
df = reader.today_df()
print(df)
# sum
japan = df.loc[['Japan', 'Diamond Princess']].sum(numeric_only=True)
# update
df.loc['Japan'] = japan
df = df.drop('Diamond Princess')
print(df.loc[['Japan']])
El jue., 9 de abr. de 2020 a la(s) 17:51, Marco Cheung (
notifications@github.com) escribió:
… @efra-mx <https://github.com/efra-mx> Thanks for follow-up. However, the
result does not what I expect.
I checked all column fields are now in 'object' datatype. How can I change
to float/int so that it can be grouped properly?
[image: image]
<https://user-images.githubusercontent.com/29329279/78914184-a4782900-7abc-11ea-8d3d-5a479aa63230.png>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1642 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB5C7W5SRAC3BFLJX6QXMDLRLXVGPANCNFSM4LUO3NVQ>
.
|
Thanks @efra-mx! That works for me and sounds straightforward to understand your code with comments! |
I have this error running the code How to fix that? |
For Pandas + Python users, I propose the following code snippet to seamlessly integrate daily data from worldometers.info straight inside your legacy code generating stuff from recoveries stats @jhu (as we all know, this data stream is now discontinued and we are left on our own, so to say)
IMPORTANT:
OUTPUT:
The text was updated successfully, but these errors were encountered: