Danny
Danny

Reputation: 403

Reading txt files into python as dataframe

I'm trying to read the FEC's "contributions by individuals" (indiv18.zip), (available here: https://classic.fec.gov/finance/disclosure/ftpdet.shtml#a2017_2018) into python. It comes downloaded into several .txt files. I'm very new and I'm confused how I can read these files into python. Thanks so much!

Upvotes: 0

Views: 99

Answers (1)

Richard Rublev
Richard Rublev

Reputation: 8172

Download the file first,then unzip it

Try this code

import pandas as pd

with open("cm.txt", "r", newline="") as f:
    table = pd.read_table(f, sep='|',lineterminator='\n')

print (table[:0])

Output

Empty DataFrame
Columns: [C00000018, IRONWORKERS LOCAL UNION NO. 25 POLITICAL EDUCATION COMMITTEE, STEVEN N GULICK, 43335 W 10 MILE, P O BOX 965, NOVI, MI, 48050, U, Q, Unnamed: 10, T, Unnamed: 12, IRON WORKERS; INT'L ASS'N OF BRIDGE..., H8TX22313]
Index: []

Read about pandas.read_table

Upvotes: 1

Related Questions