|
3 | 3 | from codeinsight_sdk.client import CodeInsightClient |
4 | 4 |
|
5 | 5 | print("Example 9: Working with Pandas DataFrames") |
6 | | -PROJECT_ID = 1 # Update this to your project ID |
| 6 | +PROJECT_ID = 1 # Update this to your project ID |
7 | 7 |
|
8 | | -client = CodeInsightClient(shared.BASE_URL, shared.AUTH_TOKEN,experimental=True) |
| 8 | +client = CodeInsightClient(shared.BASE_URL, shared.AUTH_TOKEN, experimental=True) |
9 | 9 |
|
10 | 10 | # Get all the project vulnerabilities. |
11 | 11 | # This will return a list of Vulnerability objects. |
|
16 | 16 |
|
17 | 17 | # Now "explode" list of vulnerabilities into separate rows. |
18 | 18 | # This will create a new row for each vulnerability. |
19 | | -df = df.explode('vulnerabilities', ignore_index=True) |
| 19 | +df = df.explode("vulnerabilities", ignore_index=True) |
20 | 20 |
|
21 | 21 | # Next we convert the vulnerabilities column into another DataFrame |
22 | 22 | # and then merge it back into the original DataFrame so that we can |
23 | 23 | # access the vulnerability properties as columns. |
24 | | -df_vul = pd.json_normalize(df['vulnerabilities']) |
| 24 | +df_vul = pd.json_normalize(df["vulnerabilities"]) |
25 | 25 | df = df.merge(df_vul, left_index=True, right_index=True) |
26 | 26 |
|
27 | 27 | # Optionally we can drop the original vulnerabilities column |
28 | 28 | # since we no longer need it. You can also drop other columns |
29 | | -df.drop(columns=['vulnerabilities'],inplace=True) |
| 29 | +df.drop(columns=["vulnerabilities"], inplace=True) |
30 | 30 |
|
31 | 31 | # Finally we write the output to excel |
32 | | -df.to_excel('example-9-output.xlsx', index=False) |
| 32 | +df.to_excel("example-9-output.xlsx", index=False) |
0 commit comments