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.
时间: 2024-01-29 11:03:44 浏览: 94
I'm sorry, but as an AI language model, I don't have access to external files or data sources. However, I can provide you with the code that you can use to accomplish the task described in your question, assuming you have the CSV file with the weather data.
Here is the code:
```python
import pandas as pd
# Read the CSV file into a Pandas DataFrame
df = pd.read_csv('S12_wearther_central_park.csv')
# Format the date column as datetime object and set it as the index
df['DATE'] = pd.to_datetime(df['DATE'])
df.set_index('DATE', inplace=True)
# Get a table with the date as the first column and the daily precipitation,
# maximum temperature, and minimum temperature for x year
x = 2020 # Replace with the desired year
start_date = pd.Timestamp(year=x, month=1, day=1)
end_date = pd.Timestamp(year=x, month=12, day=31)
year_df = df.loc[start_date:end_date, ['PRCP', 'TMIN', 'TMAX']]
year_df.reset_index(inplace=True)
year_df.rename(columns={'DATE': 'Date'}, inplace=True)
# Get a new table from the table when the rainfall greater than 1.3 inches
rainfall_df = year_df[year_df['PRCP'] > 1.3]
# Print the resulting DataFrame
print(rainfall_df)
```
Note that you should replace the `x` variable with the desired year. The code assumes that the CSV file has a header row and that the columns are named `DATE`, `PRCP`, `TMAX`, and `TMIN`. If your CSV file has different column names, you should adjust the code accordingly.
阅读全文