我想讀取一個csv作爲數據幀到Pandas中。Csv與熊貓數據框缺失列
我的CSV文件格式如下
a b c d
0 1 2 3 4 5
1 2 3 4 5 6
當我讀到有大熊貓,我得到以下數據框
a b c d
0 1 2 3 4 5
1 2 3 4 5 6
的CSV當我執行print df.columns
我得到的是這樣的:
Index([u'a', u'b', u'c', u'd'], dtype='object')
而當我執行print df.iloc[0]
我得到:
a 2
b 3
c 4
d 5
Name: (0, 1)
我想有一個東西像數據幀
a b c d col1 col2
0 1 2 3 4 5
1 2 3 4 5 6
我不知道我有多少列必須有。但是我需要在標題之後的第一行中包含多少個值。我怎樣才能做到這一點?
這【答案】(https://stackoverflow.com/questions/34358196/read-csv-with-missing-incomplete-header-or-irregular-number-of-列)可以幫助 – floatingpurr