python - Import difficulties with read_csv -
i have csv-file following format:
0;2017-02-16 15:08:16;81,307877;;;;;;;
so, semi-colon separator, date , time , float decimal comma. , bunch of semi-colons in end.
pandas csv_read should solution this. however, after plenty of attempts feel rather stuck. not understand how handle ;;;'s in end of file , rather uncertain whether understand how csv_read works when comes more detailed control possibilities.
for using csv_read regularily, has simple question... hope. have spent quite time on already...
one example:
pd.read_csv(r'c:\users\henrik\pycharmprojects\regforce\kort_del_1.csv', encoding="latin", sep=';', decimal=',', usecols=[0, 1, 2, 3])
in return get:
ÿþ0 unnamed: 1 unnamed: 2 unnamed: 3 0 nan nan nan nan 1 nan nan nan nan
i have tried "force" types each of columns no result...???
update: found interesting post, http://pythonforengineers.com/website-visitors-part-2-dealing-with-corrupt-data/... downloaded hex-reader , found odd things in beginning of input file. seems reason behind "ÿþ0" in table above. cannot see if open in notebook sure in file.
can origin nan's in file? , how handle it? seems read_csv able identify existence of columns, cannot values...?
i use read_csv
in way:
df = pd.read_csv('yourfile.csv', sep=';', header=none, decimal=',', usecols=[0,1,2])
so reading , since have semi-colons @ end you're not interested in, consider first 3 columns.
edit: pirsquared comment, add decimal=','
args.
Comments
Post a Comment