我正在尝试将以下csv文件格式读取到pandas DataFrame
"Indikator";"Grupp";"2014M04";"2014M05";"2014M06";"2014M07";"2014M08";"2014M09";"2014M10";"2014M11";"2014M12";"2015M01";"2015M02";"2015M03";"2015M04";"2015M05";"2015M06";"2015M07";"2015M08";"2015M09";"2015M10";"2015M11";"2015M12";"2016M01"
"Konfidensindikatorhushåll(CCI)";"Alla";100.3;102.1;101.8;100.4;95.7;102.0;97.8;98.3;98.4;98.8;97.5;100.7;97.2;99.1;98.0;96.4;99.8;98.2;98.9;96.2;98.6;97.5
第一行是日期,第二行是值。我有什么建议可以解决这个问题?
提前谢谢!
答案 0 :(得分:1)
您可以将常用pd.read_csv
与header=None
一起使用,然后转置您的数据框:
df = pd.read_csv('your_file', sep=';', header=None)
In [31]: df.T
Out[31]:
0 1
0 Indikator Konfidensindikatorhushåll(CCI)
1 Grupp Alla
2 2014M04 100.3
3 2014M05 102.1
4 2014M06 101.8
5 2014M07 100.4
6 2014M08 95.7
7 2014M09 102.0
8 2014M10 97.8
9 2014M11 98.3
10 2014M12 98.4
11 2015M01 98.8
12 2015M02 97.5
13 2015M03 100.7
14 2015M04 97.2
15 2015M05 99.1
16 2015M06 98.0
17 2015M07 96.4
18 2015M08 99.8
19 2015M09 98.2
20 2015M10 98.9
21 2015M11 96.2
22 2015M12 98.6
23 2016M01 97.5