Round columns in pandas dataframe

0 votes

I have got the following pandas data frame

          Y         X id WP_NER
0 35.973496 -2.734554  1  WP_01 
1 35.592138 -2.903913  2  WP_02 
2 35.329853 -3.391070  3  WP_03 
3 35.392608 -3.928513  4  WP_04 
4 35.579265 -3.942995  5  WP_05 
5 35.519728 -3.408771  6  WP_06 
6 35.759485 -3.078903 7 WP_07 

I´d like to round Y and X columns using pandas. How do I do this?

Jul 4, 2019 in Python by ana1504.k
• 7,910 points
2,083 views

1 answer to this question.

0 votes

You can now, use round on dataframe

The code will be:

In [661]: df.round({'Y': 2, 'X': 2})
Out[661]:
       Y     X  id WP_NER
0  35.97 -2.73   1  WP_01
1  35.59 -2.90   2  WP_02
2  35.33 -3.39   3  WP_03
3  35.39 -3.93   4  WP_04
4  35.58 -3.94   5  WP_05
5  35.52 -3.41   6  WP_06
6  35.76 -3.08   7  WP_07
answered Jul 4, 2019 by SDeb
• 13,300 points

Related Questions In Python

0 votes
1 answer
0 votes
0 answers

how do sort the columns in a dataframe using the pandas?

can you give an example using dataframe? READ MORE

May 6, 2019 in Python by Waseem
• 4,540 points
651 views
0 votes
1 answer

How to convert multiple columns to string in pandas dataframe?

Hi, To convert multiple columns to string, include a list of ...READ MORE

answered Jul 19, 2019 in Python by Taj
• 1,080 points
27,866 views
0 votes
1 answer

How to add multiple columns to pandas dataframe in one assignment?

Hello @kartik, You could use assign with a dict of ...READ MORE

answered Jun 15, 2020 in Python by Niroj
• 82,840 points
15,933 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
0 votes
1 answer

df.mul vs df.rmul in Pandas

The documentation is not identical. As stated ...READ MORE

answered Jan 18, 2019 in Python by SDeb
• 13,300 points
1,171 views
0 votes
1 answer

Add one row to pandas DataFrame

You can try the following : >>> import ...READ MORE

answered Mar 2, 2019 in Python by SDeb
• 13,300 points
1,131 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP