Read the weather data for Central Park in New York City between Jan 1, 2000 and Dec 31, 2020 in the file S12_wearther_central_park.csv into a Pandas DataFrame. Format the date as datetime object and set to be the DataFrame index. Get a table with the date as the first column and the daily precipitation, maximum temperature, and minimum temperature for x year. The headings for those data are PRCP, TMIN, and TMAX, respectively. Finally, get a new table from the table when the rainfall greater than 1.3 inches and print out.
时间: 2024-02-22 14:56:48 浏览: 76
vc调用goolge天气预报接口(原创)
4星 · 用户满意度95%
Sure, I can help you with that! Here's the Python code to accomplish these tasks using Pandas:
```python
import pandas as pd
# read CSV file into a Pandas DataFrame
df = pd.read_csv('S12_weather_central_park.csv')
# convert date column to datetime object and set as index
df['DATE'] = pd.to_datetime(df['DATE'])
df.set_index('DATE', inplace=True)
# extract year from index and group by year
df_year = df.groupby(df.index.year)
# create table with date as first column and daily precipitation,
# maximum temperature, and minimum temperature for each year
table = pd.DataFrame()
for year, data in df_year:
table[year] = data[['PRCP', 'TMIN', 'TMAX']].mean()
table.index.name = 'Date'
# filter the table to include only rows where rainfall is greater than 1.3 inches
table_rain = table[table['PRCP'] > 1.3]
# print the resulting table
print(table_rain)
```
This code reads the CSV file into a Pandas DataFrame, converts the date column to a datetime object and sets it as the index. It then groups the data by year and calculates the mean daily precipitation, maximum temperature, and minimum temperature for each year. The resulting table has the date as the first column and the calculated values for each year in subsequent columns. Finally, it filters the table to include only rows where the rainfall is greater than 1.3 inches and prints the resulting table.
阅读全文