Python pandas parsed the table, but the number of rows cannot be parsed as per the site at any site.
Here's the code.
import pandas as pd
url='https://weather.time-j.net/'
dfs=pd.read_html(url)
print(dfs[1].head())
Results.
City name: Today's highest temperature, average temperature, record up to yesterday this season
City name: Today's highest temperature, the highest temperature, the average day, the highest temperature, the lowest day, the number of days in the middle of winter.
0 Sapporo 8.8°C 2.5°C - 3.0°C December 4th - 5th
1 Sendai 16.2°C 8.9°C 5.3°C December 5th 0th
2 Tokyo 15.3°C 12.5°C 7.1°C December 7th 0th
3 Nagoya 15.7°C 12.2°C 8.0°C December 7th 0th
4 Niigata 14.8°C 9.3°C 6.2°C December 6th 0th
df=dfs[1].loc[2:,:]
df.columns=['City Name', 'Yesterday's High Temperature', 'High Temperature Average', 'High Temperature Lowest Temperature', 'Date of Rise', 'Day of Midwinter']
How about
Extract only the data portion of the data frame (line 3 or later) in the first line program,
The second line of the program redefines the column name.
© 2024 OneMinuteCode. All rights reserved.