1

I'm trying to pull out the rows from these CSVs where the state is "Pennsylvania": https://github.com/CSSEGISandData/COVID-19/tree/master/csse_covid_19_data/csse_covid_19_daily_reports_us

I have this code:

import glob
import pandas as pd

df = []

path = "/home/reallymemorable/Documents/git/COVID-19/csse_covid_19_data/csse_covid_19_daily_reports_us/*.csv"
for fname in glob.glob(path):
    row = df.loc[df['Province_State'] == 'Pennsylvania']
    print(row)

I'm getting this error:

AttributeError: 'list' object has no attribute 'loc'

I understand that it's expecting a DataFrame but I've set df as a list. But I don't know how to make it a DataFrame so that my pattern matching works correctly.

What am I doing wrong?

0

1 Answer 1

1

In your code, df is the empty list [] that you define at the beginning, not a Pandas DataFrame. Did you forget to load the data:

path = "/home/reallymemorable/Documents/git/COVID-19/csse_covid_19_data/csse_covid_19_daily_reports_us/*.csv"
for fname in glob.glob(path):
    df = pd.read_csv(fname)   # this line???
    row = df.loc[df['Province_State'] == 'Pennsylvania']
    print(row)
Sign up to request clarification or add additional context in comments.

1 Comment

...Is it obvious that I haven't used Python in a while?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.