I need modify a csv file with pandas. I have the following table:
Interface Description
1 Used
2 Used
3 Used
4 Used
6 Used
8 Used
12 Used
17 Used
I need to match the "Interface" column with a range of 1, 20, complete the table with the missing numbers and place the word "free" in the "Description" column and order it like this:
Interface Description
1 Used
2 Used
3 Used
4 Used
5 free
6 Used
7 free
8 Used
9 free
10 free
11 free
12 Used
13 free
14 free
15 free
16 free
17 Used
18 free
19 free
20 free
Use merge
in combination with fillna
df = pd.DataFrame({
'Interface': [1, 2, 3, 4, 6, 8, 12, 17],
'Description': 'Used'})
df2 = pd.DataFrame({'Interface': range(1, 21)}).merge(df, how="left").fillna("free")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With