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-30 19:04:31 浏览: 73
Sure, here's how you can do it in Python using Pandas:
```python
import pandas as pd
# Read the CSV file into a DataFrame
df = pd.read_csv('S12_wearther_central_park.csv')
# Convert the date column to datetime and set as index
df['DATE'] = pd.to_datetime(df['DATE'])
df.set_index('DATE', inplace=True)
# Create a new DataFrame with the desired columns for x year
x = 2010
year_df = df.loc[str(x), ['PRCP', 'TMIN', 'TMAX']]
# Filter the DataFrame for rainfall greater than 1.3 inches
rainy_days = year_df[year_df['PRCP'] > 1.3]
# Print the resulting DataFrame
print(rainy_days)
```
This code reads the weather data from the CSV file into a DataFrame, converts the date column to datetime and sets it as the index. It then creates a new DataFrame with the precipitation, minimum temperature, and maximum temperature for the specified year (in this case, 2010). Finally, it filters the DataFrame to only include days with rainfall greater than 1.3 inches and prints the resulting DataFrame. You can change the value of `x` to get data for a different year.
阅读全文