@@ -6,7 +6,7 @@ def f_367(file_path="data.csv", columns=["A", "B", "C"]):
66 """
77 Read a CSV file into a Pandas DataFrame, convert numeric values into floats,and draw a line chart of data in the specified columns.
88 In addition, compute the cube-root of the data.
9-
9+
1010 Parameters:
1111 - file_path (str): Path to the CSV file. Default is 'data.csv'.
1212 - columns (list of str): List of column names from the data to plot.
@@ -17,7 +17,7 @@ def f_367(file_path="data.csv", columns=["A", "B", "C"]):
1717 - DataFrame: A pandas DataFrame of the data in the CSV file.
1818 - Axes: A matplotlib Axes object showing the plotted data.
1919 - Series: A pandas Series containing the cube-root of the data.
20-
20+
2121 Requirements:
2222 - pandas
2323 - numpy
@@ -31,7 +31,7 @@ def f_367(file_path="data.csv", columns=["A", "B", "C"]):
3131 >>> ax
3232 <matplotlib.axes._subplots.AxesSubplot object at 0x7f24b00f4a90>
3333 >>> croot
34- 0 1.0
34+ 0 1.0
3535 """
3636 df = pd .read_csv (file_path , dtype = float )
3737 ax = df [columns ].plot ()
@@ -46,6 +46,11 @@ def f_367(file_path="data.csv", columns=["A", "B", "C"]):
4646import os
4747
4848
49+ def round_dict (d , digits ):
50+ return {k : {i : round (v , digits ) for i , v in subdict .items ()} for k , subdict in
51+ d .items ()}
52+
53+
4954class TestCases (unittest .TestCase ):
5055 def setUp (self ):
5156 self .test_dir = tempfile .TemporaryDirectory ()
@@ -87,8 +92,13 @@ def test_case_1(self):
8792 self .assertTrue ((df ["A" ].tolist () == [1 , 2 , 3 ]))
8893 self .assertTrue ((df ["B" ].tolist () == [4 , 5 , 6 ]))
8994 self .assertTrue ((df ["C" ].tolist () == [7 , 8 , 9 ]))
90- self .assertEqual (croot .to_dict (), {'A' : {0 : 1.0 , 1 : 1.2599210498948734 , 2 : 1.4422495703074083 }, 'B' : {0 : 1.5874010519681996 , 1 : 1.7099759466766968 , 2 : 1.8171205928321394 }, 'C' : {0 : 1.9129311827723894 , 1 : 2.0 , 2 : 2.080083823051904 }})
91-
95+ rounded_croot = round_dict (croot .to_dict (), 6 )
96+ self .assertEqual (rounded_croot ,
97+ {'A' : {0 : 1.0 , 1 : 1.259921 , 2 : 1.44225 },
98+ 'B' : {0 : 1.587401 , 1 : 1.709976 ,
99+ 2 : 1.817121 },
100+ 'C' : {0 : 1.912931 , 1 : 2.0 , 2 : 2.080084 }})
101+
92102 def test_case_2 (self ):
93103 file_path = self .temp_files ["int" ]
94104 with self .assertRaises (KeyError ):
@@ -104,8 +114,14 @@ def test_case_3(self):
104114 self .assertTrue (df ["IntColumn" ].equals (pd .Series ([1.0 , 2.0 , 3.0 ])))
105115 self .assertTrue (df ["FloatColumn" ].equals (pd .Series ([1.1 , 2.2 , 3.3 ])))
106116 self .assertTrue (df ["StringColumn" ].equals (pd .Series ([4.0 , 5.0 , 6.0 ])))
107- self .assertEqual (croot .to_dict (), {'IntColumn' : {0 : 1.0 , 1 : 1.2599210498948734 , 2 : 1.4422495703074083 }, 'FloatColumn' : {0 : 1.0322801154563672 , 1 : 1.300591446851387 , 2 : 1.4888055529538275 }, 'StringColumn' : {0 : 1.5874010519681996 , 1 : 1.7099759466766968 , 2 : 1.8171205928321394 }})
108-
117+ rounded_croot = round_dict (croot .to_dict (), 6 )
118+ self .assertEqual (rounded_croot , {
119+ 'IntColumn' : {0 : 1.0 , 1 : 1.259921 , 2 : 1.44225 },
120+ 'FloatColumn' : {0 : 1.03228 , 1 : 1.300591 ,
121+ 2 : 1.488806 },
122+ 'StringColumn' : {0 : 1.587401 , 1 : 1.709976 ,
123+ 2 : 1.817121 }})
124+
109125 def test_case_4 (self ):
110126 file_path = self .temp_files ["varied_invalid" ]
111127 with self .assertRaises (Exception ):
0 commit comments