Most voted "pandas" questions
Pandas is an open source library, which provides high performance data structures and data analysis tools for the Python programming language.
Learn more…646 questions
Sort by count of
-
8
votes1
answer1603
viewsFormat percentage in python
How should I format the percentage for this example? import pandas as pd flights = pd.read_csv('data/flights_until_june.csv', sep=',') sum_null = flights.isnull().sum()…
-
7
votes6
answers19845
viewsHow to change the name of the pandas dataframe column?
I am using pandas to process a CSV file in the following structure: nome;idade Fulano;28 Joao da Silva;27 Maria;29 The reading of the file is done as follows: import pandas as pd df =…
-
5
votes1
answer23453
viewsHow to filter, select and count data on a pandas.Dataframe?
How to get quantity of records based on multiple columns of a given name? My dataframe looks something like this: import pandas as pd df = pd.DataFrame([["1111", True, True, False, True, True],…
-
5
votes1
answer1933
viewsSwap String part in all dataframe columns
I have a dataframe in the following template: lista = [] lista.append(['A1','2','A3']) lista.append(['4','A5','6']) lista.append(['A7','8','9']) df = pd.DataFrame(lista, columns=['A', 'B', 'C']) df:…
-
5
votes2
answers260
viewsIn Python, how do you remove specific characters from all the records of just one particular column?
I’m at Jupyter Notebook working with Python. The dataframe has some columns, but in a specific column I want to delete all records that end with ". txt", meaning the last 4 characters. Image of the…
-
5
votes1
answer236
viewsWhat do you mean, "Empty Dataframe"?
I’m learning and doing a lesson from my college. My teacher asked to use format table filters .csv using the command .query() So original is like this: Funcionario Escolaridade Genero Idade Meses…
-
4
votes3
answers2125
viewsFormat Time in a Python data frame
I’m trying to format the column that brings the hours with milesimos, that is, to take milesimos and visualize hh:mm:ss only.…
-
4
votes1
answer2305
viewsAdd new data in an empty pandas dataframe
I am creating code to read several CSV files and extract some parameters from it and assemble a new dataframe with pandas, however I am facing a problem in this construction. Initially intended to…
-
4
votes3
answers11645
viewsUsing Groupby in Pandas dataframe
good afternoon. I don’t have much skill with Python, I’m having some doubts. Anyone who can help me, I thank you. I opened my csv file in python as follows: import pandas as pd caminhoArquivo =…
-
4
votes3
answers125
viewsHow to add one column of data based on another in excel through Pandas?
I have a spreadsheet with multiple import data. The problem is always the format as the data comes. For example, I have a column called "Imported Goods" that has values like the below: 1 X 40…
-
4
votes1
answer53
viewsRelate two dataframes using python logic
Hello, I need to relate the two dataframes below using conditions (i) if df1 cat is in the tuple of the df2 cat column; and (ii) the event column. The result should be a column 'Resp' in df1 that…
-
3
votes1
answer8603
viewsGrouping and aggregating data
I have the following file on CSV (12 Millions of records): UF Municipio Cod NIS Valor Data MA IMPERATRIZ 803 16361947271 45.00 01/01/2011 MA IMPERATRIZ 803 74629273937 15.00 01/01/2011 BA RUY…
-
3
votes1
answer229
viewsTypeerror: a float is required
This is my code: ### BIBLIOTECAS import scipy.special as sps import numpy as np import matplotlib.pyplot as plt import pandas as pd import scipy as sp from scipy.stats import norm from scipy.stats…
-
3
votes2
answers1079
viewsHow to compare if the contents of two columns string of a data frame are similar
I have a data frame where I need to compare how much the contents of two columns are similar. For example: coluna a = “José Luiz da Silva” and coluna b = “José L. Silva”. How can I indicate that…
-
3
votes2
answers2450
viewsGet range of values in pandas object. Dataframe
I have an object pandas. Dataframe with a python date field. How can I get a set of records according to date range? An example of the data set (last 10 records): datpre codneg nomres modref preabe…
-
3
votes1
answer6918
viewsSeparating a dataframe by some criteria - Python Pandas
I have a csv file with little more than 500 thousand lines that I would like to separate into two dataframes. The format of each line: date, time, value of interest variable dd-mm-yy,hh:mm:00,float…
-
3
votes1
answer173
viewsPandas Python, I’m having trouble figuring out which store sold the most in the last month
I have problem to know how I do to get the last month that in the case and the month 2018/02 to can strip the average of who sold the most in this month. import pandas as pd % matplotlib inline df =…
-
3
votes1
answer447
viewsImport CSV to Pandas database without converting string to tuple
I upload a CSV file with more than 3 million lines and about 770 Mb, I use pandas and need to convert a column that is in string format. Below the column 'lbBins', which when reading from CSV came…
-
3
votes1
answer817
viewsHow to solve this encoding error (encoding error) in Pandas
I’m having trouble when python reads the xlsx with pandas. When it runs the des_pt = (f_pt.head()[pt][0]).encode('utf-8').strip() and puts the variable pt. Has an Encode problem because some…
-
3
votes2
answers3465
viewsHow to invert the order of columns of a Dataframe with Python
Oops, I wonder how I can invert entire columns with using python. FRUTA | VITAMINA | PREÇO LARANJA | C | 2.00 MAÇÃ | B1 | 2.00 BANANA | B2 | 1.00 I would like to know how I can transform the…
-
3
votes1
answer1217
viewsGrouping table groupby pandas
I have a table in this format User Material Nota 1 youtube 5 2 facebook 4 3 facebook 3 4 facebook 5 6 youtube 2 7 orkut 3 8 twitter 4 and would like to group so that in the final table shows only…
-
3
votes2
answers120
viewsTable grouping
I have this table and would like to put together a list or another table users_ID_User Material Rating 0 A "Hey Pogo!...from citation to fulltext" 5 1 B "Hey Pogo!...from citation to fulltext" 4 2 C…
-
3
votes1
answer713
viewsFind most repeated value
I’m trying to analyze some shoe sales data, but I’m having a hard time creating a function to find out which number the customer bought the most in the previous year. I have a table with this data:…
-
3
votes3
answers398
viewsIntersection between pandas columns
Considering two dataframes like the ones below: import pandas as pd df = pd.DataFrame({'id':[3,6,9,12,15]}) df1 = pd.DataFrame({'id': [2,4,6,8,10,12,14]}) How to account for the intersection between…
-
3
votes1
answer1112
viewsCount number of unique records in a Data Frame
I have a base with a column custumer_id and I need to know the amount of unique records on the base. quantidade_clientes = df[['customer_id']] quantidade_clientes.count() This way I count everyone,…
-
3
votes1
answer1343
viewsThe Truth value of a Series is ambiguous. Use a.Empty, a.bool(), a.item(), a.any() or a.all()
I am a layperson in programming, in the stackoverflow community and I am not able to solve the following problem: Create two lists (or if you prefer 2 columns in a New Dataframe) in which you search…
-
3
votes1
answer97
viewsHow to compare two string values with pandas?
Hello! I have two pandas dataframes and selected a column of each with ids. I want to compare the ids to see if the id of one dataframe is contained in another, but it does not have the same amount…
-
3
votes2
answers301
viewspython np.Where with two conditions
Hello, I have the following dataframe: import pandas as pd import numpy as np x = pd.DataFrame({'A': [1,2,3,0], 'B': [5,0,0,1]}) What I want is to create a column’D', which is True if the two…
-
3
votes2
answers97
viewsHow to filter rows where columns meet consecutive conditions in Python?
I’m trying to filter lines in which the columns comply with conditions consecutively. That is, if the row has columns with the conditions of after an L/I, the next column has a A/S, then return the…
-
3
votes1
answer65
viewsReplace strings with list elements
# Código list = [a for a in range(100,103)] df = pd.DataFrame({ "A":['x','y','z'], "B":[0,1,2], "C":[0,0,0] }) I need to replace column strings C by the strings of list, so that the first string of…
-
3
votes1
answer126
viewsFastest way to iterate over lines in python, pandas
I’m having a certain performance difficulty in the code because it’s taking too long to run. I have the following Dataframe. (Example because what I’m wearing is much bigger) orders = {'Código':…
-
3
votes1
answer41
viewsPivoting in Pandas
Hey there, guys. I have a table in pandas and would like to turn the values in the column DE_ANALITO into columns whose values would be what is in the column DE_RESULTADO.…
-
3
votes2
answers172
viewsSelect Dataframe lines based on list of values for a column
I have a Dataframe with more than 5 thousand lines and more than 20 columns. I want to select only a few rows, second column match criteria with specific values SELECT * FROM dataframe WHERE…
-
3
votes2
answers88
viewsReplacing Nan values with the subsequent not Nan of another column
I have a Dataframe with some columns (I’m only representing two in this post). I need to fill the Nan of one column with certain values of another. See below: Creating the Test Dataframe…
-
3
votes1
answer42
viewsCreate a column filled with 0 or 1 based on other columns in Pandas
I have a data frame and need to fill a column with 0 or 1 based on the values of another 29 columns. If you have 1 in any of the columns 0 to 28 the column with Dor_leve receives 1, otherwise…
-
2
votes4
answers13845
viewsHow to install the Pandas library in Python 3
I would like to know how to install the Pandas library in Manjaro, in Python version 3.4.3 -
-
2
votes1
answer401
viewsCreating data set for sklearn with dataframe pandas
I have the following situation from sklearn.linear_model import LogisticRegression import pandas as pd x = pd.DataFrame({'A':[1,3,8,6,1],'B':[2,6,9,3,2]}) y = pd.DataFrame({'C':[8,6,3,6,1]}) How do…
-
2
votes1
answer4048
viewsRead csv file using "|" - Python character as delimiter
I tried to create a Dataframe with the pandas lib of a file that is sent to me in the following format: -------------------------------- |Indice|Preço|Quantidade|Cidade|…
-
2
votes1
answer578
viewsCompare fields in two datasets
Considering two sets of read data from type files *.CSV with the Pandas. Each set has only one field CPF Favorecido,where there are millions of records. Each data set is equivalent to one month. I…
-
2
votes1
answer2763
viewsImporting data using pandas in python
Good afternoon Personal! I am trying to import a csv file using the pandas package in Python import pandas as pd names_col = ['AnoInfracao', 'TrimestreInfracao', 'CodigoInfracao',…
-
2
votes2
answers1095
viewsAdd a new value at the beginning of a pandas series
How do I add a new value to a pandas series? I made the copy of the dataframe series and now I need to add a new value to the series swap_hoje, but instead of being at the end of the series, I need…
-
2
votes1
answer725
viewsRemove duplicate dates by summing the values
I need to remove duplicate dates from the dataframe and add the values corresponding to those dates. I found an answer in the NA stack that approaches what I need, but I couldn’t shape it for my…
-
2
votes1
answer546
viewsPython Pandas: regravando pd.read_table() with original comments
I have a tab-separated file in which the first lines are comments designated with '#'. I use the following code to pull the file without the comments... The file is something like: #comentario…
-
2
votes2
answers972
viewsPython fill values with data from other lines
Good morning, I’m having a major data failure problem in my df. I need to find the value of CO2 similar to that of another time using conditions that I am not able to do with the information on the…
-
2
votes3
answers7021
viewsHow to change the type of a column in Pandas?
I want to change the type of a column of a CSV file. I used this command: cand_doacoes['CPF_CNPJ_doador'] = cand_doacoes.CPF_CNPJ_doador.astype(int64) But the error appears: NameError Traceback…
-
2
votes0
answers785
viewsPython Pandas CSV
I started to learn Python not long ago and I’m doing a project to normalize customer data. But I don’t know how to make a comparison like: read on CSV field CP7, search for all CP7 of CSV CTT and…
-
2
votes1
answer5572
viewsPandas - select lines
Hello. How do I select a specific line in a dataframe? df1=pd.read_csv('arquivo1.csv', encoding='ISO-8859-1', sep=";") I’ve tried to do df.index[2], but gives error. The 2 is the line I want.…
-
2
votes1
answer988
viewsPython - invalid literal for float()
I have an array that looks like this training_set = [['03/11/2017' '16,94'] ['01/11/2017' '16,90'] ['31/10/2017' '16,77'] ... However, I cannot manipulate the numbers because they are in the form of…
-
2
votes2
answers1093
viewsGroup by week
I have a table like this I’m trying to separate by week, I don’t have much knowledge in which functions I can use to check how many weeks you have between these dates, to then group. The data is in…
-
2
votes1
answer1889
viewsHow do I filter data by date on a dataframe (Python)
Since you would have to create a new dataframe with the information coming from these dates below. import pandas as pd import numpy as np import datetime %matplotlib inline races =…