Seite 1 von 1

csv Datei Zeilenüberschrift wählen und header entfernen

Verfasst: Donnerstag 22. Juli 2021, 13:15
von Brando
Hallo,

beim Importieren einer csv Datei wähle ich:
GDP = pd.read_csv("assets/world_bank.csv", sep=",", header= None)

Nun erhalte ich u.a.
0 1 2 \
4 Country Name Country Code Indicator Name
5 Aruba ABW GDP at market prices (constant 2010 US$)
6 Andorra AND GDP at market prices (constant 2010 US$)
7 Afghanistan AFG GDP at market prices (constant 2010 US$)
8 Angola AGO GDP at market prices (constant 2010 US$)
.. ... ... ...
264 Yemen, Rep. YEM GDP at market prices (constant 2010 US$)
265 South Africa ZAF GDP at market prices (constant 2010 US$)
266 Congo, Dem. Rep. COD GDP at market prices (constant 2010 US$)
267 Zambia ZMB GDP at market prices (constant 2010 US$)
268 Zimbabwe ZWE GDP at market prices (constant 2010 US$)

3 4 5 6 7 \
4 Indicator Code 1.960000e+03 1.961000e+03 1.962000e+03 1.963000e+03
5 NY.GDP.MKTP.KD NaN NaN NaN NaN

6 NY.GDP.MKTP.KD NaN NaN NaN NaN
7 NY.GDP.MKTP.KD NaN NaN NaN NaN
8 NY.GDP.MKTP.KD NaN NaN NaN NaN
.. ... ... ... ... ...
264 NY.GDP.MKTP.KD NaN NaN NaN NaN
265 NY.GDP.MKTP.KD 7.707081e+10 8.003449e+10 8.497844e+10 9.124438e+10
266 NY.GDP.MKTP.KD 1.508024e+10 1.344383e+10 1.629401e+10 1.714358e+10
267 NY.GDP.MKTP.KD 4.592975e+09 4.655503e+09 4.539542e+09 4.688093e+09
268 NY.GDP.MKTP.KD 3.338344e+09 3.549199e+09 3.600111e+09 3.824915e+09


Mein Problem dabei ist, dass ich die Zeile 4 als Tabellenüberschrift haben will, und dass die Werte nach Indikator Code ganze Zahlen sein sollen, wie in der Tabelle!
Wie skippe ich die Zahlen der ersten Spalte auch noch?

Re: csv Datei Zeilenüberschrift wählen und header entfernen

Verfasst: Donnerstag 22. Juli 2021, 13:49
von einfachTobi
Siehe https://pandas.pydata.org/docs/referenc ... d_csv.html: mit skiprows, header, dtype.