import pandas as pd url='https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-states.csv' data = pd.read_csv(url, parse_dates=['date']) data['DOW'] = data['date'].apply(lambda x: x.strftime('%A')) # if you don't want to convert date columne: # data = pd.read_csv(url) # data['DOW'] = pd.to_datetime(data['date']).apply(lambda x: x.strftime('%A')) print(data.head())
Output: date state fips cases deaths DOW
0 2020-01-21 Washington 53 1 0 Tuesday
1 2020-01-22 Washington 53 1 0 Wednesday
2 2020-01-23 Washington 53 1 0 Thursday
3 2020-01-24 Illinois 17 1 0 Friday
4 2020-01-24 Washington 53 1 0 Friday
In the example I convert date
column to datetime
object when I read the csv file. In the comments - example if you do not want to convert it
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs