When you try to read a csv file in Python, pd.read_csv() is the most common method. However, the process of decoding sometimes causes errors as below, and it may not work even you tune several arguments.
When you try to read a csv file in Python, pd.read_csv() is the most common method. However, the process of decoding sometimes causes errors as below, and it may not work even you tune several arguments. For example, encoding=’utf-8′, or engine=’python’.
‘utf-8’ codec can’t decode byte 0xaa in position 103: invalid start byte
Copy, Paste, And Work
To make life easier, I created a function with pandas and csv modules.
In my opinion, you can wrap all custom functions as your own codebase, which will raise your programming efficiency dramatically. You can refer to the other post 〈Import Custom Package/Library/Module In Python〉.
def csv_reader(file, delimiter=',', quotechar='"', header=True):
import csv
# try pd.read_csv
try:
results = pd.read_csv(file)
return results
except:
print('pd.read_csv error.')
row_list = []
with open(file, newline='') as csvfile:
spamreader = csv.reader(csvfile, delimiter=delimiter,
quotechar=quotechar)
for row in spamreader:
row_list.append(row)
# Convert to dataframe ......
if header == True:
cols = row_list[0]
df_row = row_list[1:]
results = pd.DataFrame(columns=cols,
data=df_row)
else:
results = pd.DataFrame(data=row_list)
return results






References: Gizbo Casino Test
References: Jack Casino Bonus
References: Casino Of Gold App
References: Candy96 slots
References: %random_anchor_text%
References: Online payid pokies
References: Australian pokies payid
References: Online pokies real money payid
References: Online pokies australia payid real money
References: Payid pokies instant withdrawal
References: Australian online pokies payid goodgoog.ru
References: Lollybet Free Spins
References: Lollybet Registrierung maps.google.je
References: Lollybet Casino Roulette
References: Lollybet Anmeldung
References: Lollybet No Deposit Bonus
References: Lollybet Casino Bewertung
References: Best instant payid pokies australia real money
References: Payid withdrawal pokies
References: Australia online pokies payid
References: Best instant payid pokies australia real money
References: Payid pokies online git.resacachile.cl
References: Australian online pokies payid
References: Online payid pokies
References: Best instant payid pokies australia real money
References: Hitnspin casino demo
References: Hit n spin bewertung
References: Hitnspin casino betrug cse.google.co.zw
References: Hitnspin casino forum images.google.ch
References: Lollybet Casino Mobile
References: Hitnspin casino gutscheincode
References: Monro Casino Freispiele
References: Hitnspin casino spielautomaten
References: Legiano Casino Mindesteinzahlung toolbarqueries.google.dk
References: KingMaker Casino Registrierungsbonus
References: KingMaker 100 bonus einzahlung
References: Legiano Casino Zahlungsmethoden