📜  Python|熊猫中的 pandas.to_markdown()

📅  最后修改于: 2022-05-13 01:55:11.661000             🧑  作者: Mango

Python|熊猫中的 pandas.to_markdown()

pandas.to_markdown()方法的帮助下,我们可以使用pandas.to_markdown()方法从给定的数据帧中获取降价表。

示例 #1:
在这个例子中,我们可以看到通过使用pandas.to_markdown()方法,我们可以使用这个方法从给定的数据帧中获取降价表。

# import pandas
import pandas as pd
  
df = pd.DataFrame({"A": [1, 2, 3],
                   "B": [1.1, 2.2, 3.3]}, 
                    index =['a', 'a', 'b'])
  
# Using pandas.to_markdown() method
gfg = df.to_markdown()
  
print(gfg)

输出 :

|    |   A |   B |
|:---|----:|----:|
| a  |   1 | 1.1 |
| a  |   2 | 2.2 |
| b  |   3 | 3.3 |

示例 #2:

# import pandas
import pandas as pd
  
df = pd.DataFrame({"A": [3, 4, 5],
                   "B": ['c', 'd', 'e']},
                   index =['I', 'II', 'III'])
  
# Using pandas.to_markdown() method
gfg = df.to_markdown()
  
print(gfg)

输出 :

|     |   A | B   |
|:----|----:|:----|
| I   |   3 | c   |
| II  |   4 | d   |
| III |   5 | e   |