Home > other >  Pandas data transformation problems
Pandas data transformation problems

Time:09-22

The following is a result of movielens dataset dataframe


In simple terms, is to a user on a film label unified to a line, don't know how to achieve this

CodePudding user response:

Userid movieid as statistical together? What about the other? Keep only one?

CodePudding user response:

Not only keep one, is a user of a movie played tag statistics together, such as the first user of film 60756 has three labels, is to this three tag statistics as a line,

CodePudding user response:

Writes the label?

CodePudding user response:

 import pandas as pd 


Chengji=[[2600, 100,95,100, "fe1"], [2600 100,98,99, "fe2"], [2600 100,95,98, "fe3"], [3897 74,98,97, "fe3"], [2897 74,90,96, "fe3"], [3897 74,94,93, fe4 "]]
data=https://bbs.csdn.net/topics/pd.DataFrame (chengji, columns=[' userid ', 'movid', 'timestamp', 'when', 'to'])
Print (data index, data. The columns) # vertical sequence, cross headings
Print (" * * "50," raw data ")
# data [' comprehensive ']=""
Print (data)
Data1=data. Groupby ([' userid ', 'movid']) # a single group, available ([...] [...]. ) more columns group
Data2=data1. Apply (sum)

# data2. Index. Names=[' in ', 'year']
Data2. Drop ([' userid ', 'movid], axis=1, inplace=True)
Data2. Reset_index (level=None, the drop=False, inplace=True, col_level=0, col_fill="")
Print (data2)

CodePudding user response:

Thanks brother problem solved 6 learn from brother!!!!!!!!!!!

CodePudding user response:

refer to fifth floor dog wretched and xiang wretched response:
thanks brother problem solved 6 learn from brother!!!!!!!!!!!

Just found a solution, it is the wrong case, but this applies to you
  • Related