Thursday, September 25, 2025
HomeLanguagesPython | pandas.to_markdown() in Pandas

Python | pandas.to_markdown() in Pandas

With the help of pandas.to_markdown() method, we can get the markdown table from the given dataframes by using pandas.to_markdown() method.

Syntax : pandas.to_markdown()

Return : Return the markdown table.

Example #1 :
In this example we can see that by using pandas.to_markdown() method, we are able to get the markdown table from the given dataframes by using this method.




# 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)


Output :

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

Example #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)


Output :

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

Most Popular

Dominic
32320 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6683 POSTS0 COMMENTS
Nicole Veronica
11854 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11910 POSTS0 COMMENTS
Shaida Kate Naidoo
6795 POSTS0 COMMENTS
Ted Musemwa
7071 POSTS0 COMMENTS
Thapelo Manthata
6754 POSTS0 COMMENTS
Umr Jansen
6762 POSTS0 COMMENTS