The
is very simple to use when data manipulation is done through the Pandas library, and then a brief instance is written to the CSV file:
In [1]: Import pandas as PD in [2]: data = {' Row1 ': [1,2,3, ' Biubiu '], ' row2 ': [3,1,3, ' Kaka ']} in [3]: Data out[3]: {' row1 ': [1, 2, 3, ' Biubiu '], ' row2 ': [3, 1, 3, ' Kaka ']} in [4]: DATA_DF = PD.
Dataframe (data) in [5]: DATA_DF out[5]: row1 row2 0 1 3 1 2 1 2 3 3 3 Biubiu Kaka In [6]: data_df.to_csv (' data_df.csv ') in [7]: pd.read_csv (' data_df.csv ') out[7]: unnamed:0 row1 row2 0 0 1 3 1, 1 2 1 2 2 3 3 3 3 Biubiu Kaka #index表示设定是否需要行索引, set to
False indicates that no new row index is generated #header表明是否需要列索引, set to True (the default setting) indicates the need, then the column labels for DF are saved. In [ten]: Data_df.to_csv (' data_df.csv ', index=false,header=true) in [one]: pd.read_csv (' data_df.csv ') out[11]: Row1 ro W2 0 1 3 1 2 1 2 3 3 3 Biubiu kaka in [[]: Pd.read_csv (' Data_df.csv '). Index out[12]: Ran Geindex (start=0, stop=4, Step=1) in []: Pd.read_csv (' Data_df.csv '). Index.values out[13]: Array ([0, 1, 2, 3], DTYPE=INT6 4)
with a CSV package, one line to write
in [[]: Import CSV
...: with open ("Test.csv", "W") as CSVFile:
...: writer = csv.writer (csvfile)
...: c5/> ...: #先写入columns_name ...: writer.writerow (["Index", "A_name", "B_name"])
...: # Write Multiline with writerows ...
: writer.writerows ([[[[0,1,3],[1,2,3],[2,3,4]])
...: in [M
]: Pd.read_csv (' Test.csv ')
out[15]:
index a_name b_name
0 0 1 3
1 1 2 3
2 2 3 4