0
0

More than 3 years have passed since last update.

DataFrame obeject operation to use python library pandas

Posted at

1.overview

this is python library pandas to output csv files.
how to use DataFrame object and replacement DataFrame index by dict.

2.sample

sample.py
import pandas as pd

input_csv_file_path = <input_csv_file_path>
output_csv_file_path = <output_csv_file_path> 


def no_list_to_multiple_list(no_list):
    return [index * 2 for index in no_list]


if __name__ == '__main__':
    input = pd.read_csv(filepath_or_buffer=input_csv_file_path , encoding='ms932', sep=',')
    no_list = csv_input['no'].values.tolist()
    multiple_list = [no_list_to_multiple_list(no_list) for _ in no_list]
    dic = dict(zip(no_list, multiple_list))
    input['no'].replace(dic, inplace=True)
    input.set_index(['index'], inplace=True)
    input.to_csv(output_csv_file_path)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0