Home>

I'm new to python. The explanation may be difficult to understand, but thank you.
I am thinking about creating shifts for part-time jobs. In it, I read the list of shifts as a csv file. It is as follows.

Corresponding source code
import numpy as np
import pandas as pd
#Time set
n_time = 9
time = pd.Series (f "{t + 12} o'clock" for t in range (n_time))
#Shift number
n_shiftnumber = 5
shiftnumber = pd.Series (f "shift {sn + 1}" for sn in range (n_shiftnumber))
#List of shifts
shift = pd.read_csv ('shift.csv', header = None)

I have a question here, but I want to read this and change the index part of the shift list to shift number and the column part to time.

What I tried

I changed the list of shifts as follows, but an error occurred.

#List of shifts
shift = pd.read_csv ('shift.csv', header = None, index = shiftnumber, columns = time)
shift = pd.read_csv ('shift.csv', header = None, index = shiftnumber, columns = time)
TypeError: parser_f () got an unexpected keyword argument'index'


Sorry for the childish explanation.

  • Answer # 1

    It can be set after reading as follows.

    import numpy as np
    import pandas as pd
    pd.set_option ('display.unicode.east_asian_width', True)
    #Time set
    n_time = 9
    time = pd.Series (f "{t + 12} o'clock" for t in range (n_time))
    #Shift number
    n_shiftnumber = 5
    shiftnumber = pd.Series (f "shift {sn + 1}" for sn in range (n_shiftnumber))
    #List of shifts
    shift = pd.DataFrame (np.arange (45) .reshape ((5, -1)))
    shift = shift.set_index (shiftnumber) #set index
    shift.columns = time # set column names
    print (shift)
    "" "
            12:00 13:00 14:00 15:00 16:00 17:00 18:00 19:00 20:00
    shift1 0 1 2 3 4 5 6 7 8
    shift2 9 10 11 12 13 14 15 16 17
    shift3 18 19 20 21 22 23 24 25 26
    shift4 27 28 29 30 31 32 33 34 35
    shift5 36 37 38 39 40 41 42 43 44
    "" "

Related articles