Python Forum
DataFrame.astype('category') duplicates column
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DataFrame.astype('category') duplicates column
#4
(Apr-18-2018, 07:33 AM)garikhgh0 Wrote: the Dtaframe.pivot_table does not work correctly

Was trying to reproduce, but couldn't find the error:

1
2
3
import pandas as pd
data = pd.DataFrame({'x': pd.np.random.randint(0,100,1000), 'y': pd.np.random.choice(['a', 'b', 'c'], 1000)})
pd.pivot_table(data, aggfunc=pd.np.sum, values='x', columns=['y'])
Output:
y a b c x 16924 16650 16377
1
2
3
# change column type
data.y = data.y.astype('category')
pd.pivot_table(data, aggfunc=pd.np.sum, values='x', columns=['y'])
# the result is the same...
Output:
y a b c x 16924 16650 16377
Reply


Messages In This Thread
RE: DataFrame.astype('category') duplicates column - by scidam - Apr-18-2018, 11:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Find duplicates in a pandas dataframe list column on other rows Calab 2 2,199 Sep-18-2024, 07:38 PM
Last Post: Calab
  Find strings by index from a list of indexes in a different Pandas dataframe column Calab 3 1,639 Aug-26-2024, 04:52 PM
Last Post: Calab
  Create new column in dataframe Scott 10 3,602 Jun-30-2024, 10:18 PM
Last Post: Scott
  attempt to split values from within a dataframe column mbrown009 9 5,962 Jun-20-2024, 07:59 PM
Last Post: AdamHensley
  Putting column name to dataframe, can't work. jonah88888 2 3,283 Jun-18-2024, 09:19 PM
Last Post: AdamHensley
  concat 3 columns of dataframe to one column flash77 2 2,140 Oct-03-2023, 09:29 PM
Last Post: flash77
  HTML Decoder pandas dataframe column mbrown009 3 2,707 Sep-29-2023, 05:56 PM
Last Post: deanhystad
  Add group number for duplicates atomxkai 2 1,928 Dec-08-2022, 06:08 AM
Last Post: atomxkai
  New Dataframe Column Based on Several Conditions nb1214 1 2,530 Nov-16-2021, 10:52 PM
Last Post: jefsummers
  Kaggle Titanic - new category placement snakes 0 2,235 Oct-18-2021, 07:53 PM
Last Post: snakes

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020