25 pandas的使用,转成numpy数组以及将list数组保存成csv格式的文件

import pandas as pd
pd.read_csv('C:\\Users\\hx133330\\Desktop\\test1.csv')
seriesuid coordX coordY coordZ diameter_mm Unnamed: 5
0 1.3.6.1.4.1.14519.5.2.1.6279.6001.100225287222… -128.699421 -175.319272 -298.387506 5.651471 NaN
1 1.3.6.1.4.1.14519.5.2.1.6279.6001.100225287222… 103.783651 -211.925149 -227.121250 4.224708 NaN
2 1.3.6.1.4.1.14519.5.2.1.6279.6001.100398138793… 69.639017 -140.944586 876.374496 5.786348 NaN
3 1.3.6.1.4.1.14519.5.2.1.6279.6001.100621383016… -24.013824 192.102405 -391.081276 8.143262 NaN
4 1.3.6.1.4.1.14519.5.2.1.6279.6001.100621383016… 2.441547 172.464881 -405.493732 18.545150 NaN
5 1.3.6.1.4.1.14519.5.2.1.6279.6001.100621383016… 90.931713 149.027266 -426.544715 18.208570 NaN
6 1.3.6.1.4.1.14519.5.2.1.6279.6001.100621383016… 89.540769 196.405159 -515.073322 16.381276 NaN
7 1.3.6.1.4.1.14519.5.2.1.6279.6001.100953483028… 81.509646 54.957219 -150.346423 10.362321 NaN
8 1.3.6.1.4.1.14519.5.2.1.6279.6001.102681962408… 105.055792 19.825260 -91.247251 21.089619 NaN
9 1.3.6.1.4.1.14519.5.2.1.6279.6001.104562737760… -124.834262 127.247155 -473.064479 10.465854 NaN
10 1.3.6.1.4.1.14519.5.2.1.6279.6001.105495028985… -106.901301 21.922987 -126.916900 9.745259 NaN
11 1.3.6.1.4.1.14519.5.2.1.6279.6001.106164978370… 2.263816 33.526418 -170.636950 7.168542 NaN
12 1.3.6.1.4.1.14519.5.2.1.6279.6001.106379658920… -70.550889 66.359484 -160.942932 6.642185 NaN
13 1.3.6.1.4.1.14519.5.2.1.6279.6001.106379658920… -70.660628 -29.547770 -106.903082 4.543420 NaN
14 1.3.6.1.4.1.14519.5.2.1.6279.6001.106630482085… -96.439534 9.736190 -175.037571 6.753817 NaN
15 1.3.6.1.4.1.14519.5.2.1.6279.6001.106719103982… -57.087180 74.259266 1790.494057 13.693566 NaN
file_csv = pd.read_csv('C:\\Users\\hx133330\\Desktop\\test1.csv')
type(file_csv)
pandas.core.frame.DataFrame
data_old = file_csv.values
data_old[0]
array([‘1.3.6.1.4.1.14519.5.2.1.6279.6001.100225287222365663678666836860’, -128.6994211, -175.31927180000002, -298.38750639999995, 5.651470635, nan], dtype=object)
data_new = []
import numpy as np
[1]+list(data[0:-1])
[1, ‘1.3.6.1.4.1.14519.5.2.1.6279.6001.106719103982792863757268101375’, -57.08718036, 74.25926591, 1790.494057, 13.69356578]
data_new = []
for i,data in enumerate(data_old):
#     print i,data
    data_new.append([i]+list(data[0:-1]))
data_new[0]
[0, ‘1.3.6.1.4.1.14519.5.2.1.6279.6001.100225287222365663678666836860’, -128.6994211, -175.31927180000002, -298.38750639999995, 5.651470635]
columns = ['id','seriesuid', 'coordX', 'coordY', 'coordZ', 'diameter_mm']
labeled_df = pd.DataFrame(columns=columns, data=data_new)
labeled_df
id seriesuid coordX coordY coordZ diameter_mm
0 0 1.3.6.1.4.1.14519.5.2.1.6279.6001.100225287222… -128.699421 -175.319272 -298.387506 5.651471
1 1 1.3.6.1.4.1.14519.5.2.1.6279.6001.100225287222… 103.783651 -211.925149 -227.121250 4.224708
2 2 1.3.6.1.4.1.14519.5.2.1.6279.6001.100398138793… 69.639017 -140.944586 876.374496 5.786348
3 3 1.3.6.1.4.1.14519.5.2.1.6279.6001.100621383016… -24.013824 192.102405 -391.081276 8.143262
4 4 1.3.6.1.4.1.14519.5.2.1.6279.6001.100621383016… 2.441547 172.464881 -405.493732 18.545150
5 5 1.3.6.1.4.1.14519.5.2.1.6279.6001.100621383016… 90.931713 149.027266 -426.544715 18.208570
6 6 1.3.6.1.4.1.14519.5.2.1.6279.6001.100621383016… 89.540769 196.405159 -515.073322 16.381276
7 7 1.3.6.1.4.1.14519.5.2.1.6279.6001.100953483028… 81.509646 54.957219 -150.346423 10.362321
8 8 1.3.6.1.4.1.14519.5.2.1.6279.6001.102681962408… 105.055792 19.825260 -91.247251 21.089619
9 9 1.3.6.1.4.1.14519.5.2.1.6279.6001.104562737760… -124.834262 127.247155 -473.064479 10.465854
10 10 1.3.6.1.4.1.14519.5.2.1.6279.6001.105495028985… -106.901301 21.922987 -126.916900 9.745259
11 11 1.3.6.1.4.1.14519.5.2.1.6279.6001.106164978370… 2.263816 33.526418 -170.636950 7.168542
12 12 1.3.6.1.4.1.14519.5.2.1.6279.6001.106379658920… -70.550889 66.359484 -160.942932 6.642185
13 13 1.3.6.1.4.1.14519.5.2.1.6279.6001.106379658920… -70.660628 -29.547770 -106.903082 4.543420
14 14 1.3.6.1.4.1.14519.5.2.1.6279.6001.106630482085… -96.439534 9.736190 -175.037571 6.753817
15 15 1.3.6.1.4.1.14519.5.2.1.6279.6001.106719103982… -57.087180 74.259266 1790.494057 13.693566
labeled_df.to_csv('new.csv')

你可能感兴趣的:(python)