python - Different read_csv index_col = None / 0 / False in pandas -
i used read_csv command following below:
in [20]: dataframe = pd.read_csv('d:/userinterest/output/enfp_0719/bookmark.csv', index_col=none) dataframe.head() out[20]: unnamed: 0 timestamp url visits 0 0 1.404028e+09 http://m.blog.naver.com/postview.nhn?blogid=mi... 2 1 1 1.404028e+09 http://m.facebook.com/l.php?u=http%3a%2f%2fblo... 1 2 2 1.404028e+09 market://details?id=com.kakao.story 1 3 3 1.404028e+09 https://story-api.kakao.com/upgrade/install 4 4 4 1.403889e+09 http://m.cafe.daum.net/worldcuplove/knj/173424... 1
the result shows column unnamed:0
, simillar when used index_col=false
, when used index_col=0
, result following below:
dataframe = pd.read_csv('d:/userinterest/output/enfp_0719/bookmark.csv', index_col=0) dataframe.head() out[21]: timestamp url visits 0 1.404028e+09 http://m.blog.naver.com/postview.nhn?blogid=mi... 2 1 1.404028e+09 http://m.facebook.com/l.php?u=http%3a%2f%2fblo... 1 2 1.404028e+09 market://details?id=com.kakao.story 1 3 1.404028e+09 https://story-api.kakao.com/upgrade/install 4 4 1.403889e+09 http://m.cafe.daum.net/worldcuplove/knj/173424... 1
the result did show column unnamed:0
, in here want ask, difference between index_col=none
, index_col=0
, , index_col=false
, have read documentation in this, still did not idea.
update
i think since version 0.16.1 raise error if try pass boolean index_col
avoid ambiguity
original
a lot of people confused this, specify ordinal index of column should pass int position in case 0
, confuses people when there no index column pass false
incorrect should pass none
. false
evaluate 0
hence result observe.
in [3]: import io import pandas pd t="""index,a,b 0,hello,pandas""" pd.read_csv(io.stringio(t)) out[3]: index b 0 0 hello pandas
the default value index_col=none
shown above.
if set index_col=0
we're explicitly stating treat first column index:
in [4]: pd.read_csv(io.stringio(t), index_col=0) out[4]: b index 0 hello pandas
if pass index_col=false
same result above due false
evaluating 0
:
in [5]: pd.read_csv(io.stringio(t), index_col=false) out[5]: index b 0 0 hello pandas
if state index_col=none
same behaviour when didn't pass param:
in [6]: pd.read_csv(io.stringio(t), index_col=none) out[6]: index b 0 0 hello pandas
edit
for case have blank index column have:
in [7]: import io import pandas pd t=""",a,b 0,hello,pandas""" pd.read_csv(io.stringio(t)) out[7]: unnamed: 0 b 0 0 hello pandas in [8]: pd.read_csv(io.stringio(t), index_col=0) out[8]: b 0 hello pandas in [9]: pd.read_csv(io.stringio(t), index_col=false) out[9]: unnamed: 0 b 0 0 hello pandas in [10]: pd.read_csv(io.stringio(t), index_col=none) out[10]: unnamed: 0 b 0 0 hello pandas
Comments
Post a Comment