diff --git a/pandas/core/base.py b/pandas/core/base.py index 2755c90c0ea35..a1484d9ad032b 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -714,14 +714,13 @@ def argmax( Consider dataset containing cereal calories >>> s = pd.Series( - ... { - ... { - ... "Corn Flakes": 100.0, - ... "Almond Delight": 110.0, - ... "Cinnamon Toast Crunch": 120.0, - ... "Cocoa Puff": 110.0, - ... } - ... } + ... [100.0, 110.0, 120.0, 110.0], + ... index=[ + ... "Corn Flakes", + ... "Almond Delight", + ... "Cinnamon Toast Crunch", + ... "Cocoa Puff", + ... ], ... ) >>> s Corn Flakes 100.0 diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 87bdbc0bd002d..9e8d07379ff5e 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -2828,12 +2828,7 @@ def to_stata( Examples -------- >>> df = pd.DataFrame( - ... { - ... { - ... "animal": ["falcon", "parrot", "falcon", "parrot"], - ... "speed": [350, 18, 361, 15], - ... } - ... } + ... [["falcon", 350], ["parrot", 18]], columns=["animal", "parrot"] ... ) >>> df.to_stata("animals.dta") # doctest: +SKIP """ @@ -3510,13 +3505,8 @@ def to_xml( Examples -------- >>> df = pd.DataFrame( - ... { - ... { - ... "shape": ["square", "circle", "triangle"], - ... "degrees": [360, 360, 180], - ... "sides": [4, np.nan, 3], - ... } - ... } + ... [["square", 360, 4], ["circle", 360, np.nan], ["triangle", 180, 3]], + ... columns=["shape", "degrees", "sides"], ... ) >>> df.to_xml() # doctest: +SKIP diff --git a/pandas/core/generic.py b/pandas/core/generic.py index aa8a5245b8e38..8088e41f3d034 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3933,13 +3933,8 @@ def to_csv( Create 'out.csv' containing 'df' without indices >>> df = pd.DataFrame( - ... { - ... { - ... "name": ["Raphael", "Donatello"], - ... "mask": ["red", "purple"], - ... "weapon": ["sai", "bo staff"], - ... } - ... } + ... [["Raphael", "red", "sai"], ["Donatello", "purple", "bo staff"]], + ... columns=["name", "mask", "weapon"], ... ) >>> df.to_csv("out.csv", index=False) # doctest: +SKIP @@ -5457,13 +5452,10 @@ def reindex( Create a dataframe with some fictional data. >>> index = ["Firefox", "Chrome", "Safari", "IE10", "Konqueror"] + >>> columns = ["http_status", "response_time"] >>> df = pd.DataFrame( - ... { - ... { - ... "http_status": [200, 200, 404, 404, 301], - ... "response_time": [0.04, 0.02, 0.07, 0.08, 1.0], - ... } - ... }, + ... [[200, 0.04], [200, 0.02], [404, 0.07], [404, 0.08], [301, 1.0]], + ... columns=columns, ... index=index, ... ) >>> df @@ -9678,13 +9670,8 @@ def resample( For DataFrame objects, the keyword `on` can be used to specify the column instead of the index for resampling. - >>> d = { - ... { - ... "price": [10, 11, 9, 13, 14, 18, 17, 19], - ... "volume": [50, 60, 40, 100, 50, 100, 40, 50], - ... } - ... } - >>> df = pd.DataFrame(d) + >>> df = pd.DataFrame([10, 11, 9, 13, 14, 18, 17, 19], columns=["price"]) + >>> df["volume"] = [50, 60, 40, 100, 50, 100, 40, 50] >>> df["week_starting"] = pd.date_range("01/01/2018", periods=8, freq="W") >>> df price volume week_starting @@ -9706,14 +9693,11 @@ def resample( specify on which level the resampling needs to take place. >>> days = pd.date_range("1/1/2000", periods=4, freq="D") - >>> d2 = { - ... { - ... "price": [10, 11, 9, 13, 14, 18, 17, 19], - ... "volume": [50, 60, 40, 100, 50, 100, 40, 50], - ... } - ... } >>> df2 = pd.DataFrame( - ... d2, index=pd.MultiIndex.from_product([days, ["morning", "afternoon"]]) + ... [[10, 50], + ... [11, 60], [9, 40], [13, 100], [14, 50], [18, 100], [17, 40], [19, 50]], + ... columns=["price", "volume"] + ... index=pd.MultiIndex.from_product([days, ["morning", "afternoon"]]) ... ) >>> df2 price volume diff --git a/pandas/io/xml.py b/pandas/io/xml.py index 546b5bb651564..549abb7087dbe 100644 --- a/pandas/io/xml.py +++ b/pandas/io/xml.py @@ -916,9 +916,7 @@ def read_xml( Note: if XML document uses default namespace denoted as `xmlns=''` without a prefix, you must assign any temporary namespace prefix such as 'doc' to the URI in order to parse - underlying nodes and/or attributes. For example, :: - - namespaces = {{"doc": "https://example.com"}} + underlying nodes and/or attributes. elems_only : bool, optional, default False Parse only the child elements at the specified ``xpath``. By default, @@ -987,9 +985,7 @@ def read_xml( and unlike ``xpath``, descendants do not need to relate to each other but can exist any where in document under the repeating element. This memory- efficient method should be used for very large XML files (500MB, 1GB, or 5GB+). - For example, :: - - iterparse = {{"row_element": ["child_elem", "attr", "grandchild_elem"]}} + For example, ``{{"row_element": ["child_elem", "attr", "grandchild_elem"]}}``. .. versionadded:: 1.5.0