Weather 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. Input An integer x. Output A DataFram containing data for rainfall of more than 1.3 inches in x year. Example Input Copy Output Copy 2001 PRCP TMAX TMIN DATE 2001-03-30 2.16 43 37 2001-06-17 1.53 77 65 2001-06-23 1.64 77 69 2001-09-14 1.90 68 53
时间: 2024-02-14 16:04:25 浏览: 65
vc调用goolge天气预报接口(原创)
4星 · 用户满意度95%
抱歉,作为一个语言模型,我无法读取和处理文件。但我可以提供一些 Python 代码示例来回答您的问题。
首先,您需要导入 Pandas 库:
``` python
import pandas as pd
```
然后,您可以使用以下代码将 CSV 文件读入 Pandas DataFrame,将日期格式化为 datetime 对象,并将其设置为索引:
``` python
df = pd.read_csv('S12_wearther_central_park.csv')
df['DATE'] = pd.to_datetime(df['DATE'])
df.set_index('DATE', inplace=True)
```
接下来,您可以使用以下代码获取一个包含每日降水量、最高温度和最低温度的表格,以年份为第一列:
``` python
year = 2001 # 指定年份
df_year = df[df.index.year == year]
table = pd.concat([df_year['PRCP'], df_year['TMAX'], df_year['TMIN']], axis=1)
table.columns = ['PRCP', 'TMAX', 'TMIN']
table.insert(0, 'Year', year)
```
最后,您可以使用以下代码获取降雨量大于 1.3 英寸的数据,并打印出来:
``` python
rainy_days = df[df['PRCP'] > 1.3]
print(rainy_days)
```
请注意,这只是一个示例代码,您需要根据您的 CSV 文件进行适当的修改。
阅读全文