This Python script collects temperature data for a list of cities from the OpenWeatherMap API and saves it to a CSV file.
- Python 3.x
- pandas
- requests
- Install the required libraries:
pip install pandas requests
- Create a CSV file named
cities_r2.csvwith a column named "name_of_city" containing the list of cities you want to collect data for. - Replace
YOUR_API_KEYin the script with your actual OpenWeatherMap API key. - Run the script:
python your_script_name.py
https://home.openweathermap.org/users/sign_in
- The script will print the temperature (in Kelvin) and weather description for each city to the console.
- A CSV file named
Temperature23.csvwill be created containing the city, temperature, date, and time of data collection.
- The OpenWeatherMap API has usage limits. Ensure you comply with their terms of service.
- You can modify the script to collect additional weather data or customize the output format as needed.
name_of_city
London
Paris
New York
Tokyo
City,Temperature,Date,Time
London,280.15,2023-11-28,16:32:00
Paris,282.55,2023-11-28,16:32:00
New York,275.15,2023-11-28,16:32:00
Tokyo,285.37,2023-11-28,16:32:00
Use code with caution.
Feel free to adjust the content or formatting as needed! Let me know if you need further assistance.