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
-
0
votes1
answer231
viewsCompare string PANDAS Data Science
I’m starting in this world of data science and my doubt how I can compare two string in the same column. I have a column [Investigation Type] that has 'Accident' and 'Incident' I wanted to compare…
-
0
votes1
answer3961
viewsSave data in. xlsx format with pandas
Good afternoon! I want to save in a file . xlsx the loop number that my code is running, but the way it is, saves only the last loop. import time import pandas as pd loop = 0 print('Loop') writer =…
-
0
votes2
answers2474
viewserror to import pandas library and numpy
Guys, I have a problem to import panda library and numpy for my project, when I try to run on pycharm... the following code, this error presents: code: import pandas as pd import numpy as np error:…
-
0
votes1
answer361
viewsAllocate day period to hours
I have the following df: df = pd.DataFrame({'hora completa':['21:35:00', '22:16:00', '00:50:00', '09:30:00', '14:30:00']}) print(df) hora completa 0 21:35:00 1 22:16:00 2 00:50:00 3 09:30:00 4…
-
0
votes1
answer1052
viewsCopy range of values from one Dataframe to another transposed
I would like to copy multi-range values in a df1 with 721 rows and multiple columns, and paste in a df2 transposed form. Something like that: I tried something like: df1.T…
-
0
votes1
answer826
viewsStack several txt files using pandas
I wanted to make a routine that accumulates the data I extract from google Analytics every day, but my code shows an error that I can not solve: import pandas as pd import os import glob my_dir =…
-
0
votes2
answers3821
viewsPython iloc[] function (Pandas)
I saw a code that the iloc function was like this: x = dados.iloc[0:-1, d:] y = dados.iloc[d].values[0] I read that iloc Select the row and column, but what would that be d there ?…
-
0
votes1
answer136
viewsTrasformar Datraframe in Dicionario
I ran a df from that dictionary: data = { 'Nomes': ['produto1','produto2'] 'Links': ['link1.html', 'link2.html'] 'Valores': ['R$00,00','R$00,00'] 'Tipos': ['brinquedo','aparelho'] } My doubt is how…
-
0
votes1
answer34
viewsHow to divide lines by lines of two different df and store in a third?
I try to divide using the methods div and divide and when assigning in a new df all values are as Nan…
-
0
votes2
answers159
viewsIndexing error when separating line information
import pandas as pd import numpy as np import matplotlib as plt df = pd.read_csv('dito_julho.csv') df.head() campanha valor 1 Prospect | 5 dias | Com crédito 2 2 Prospect | 5 dias | Com crédito 5 3…
-
0
votes3
answers46
viewserror in creating subplots
I am trying to create several Graphics using the following procedure: fig_2, axes = plt.subplots(2,2, figsize=(20, 5)) axes[0].plot(abril.Date_Time, abril.CPUs_pct) axes[1].plot(abril.Date_time,…
-
0
votes2
answers594
viewsHow to remove all text within a parenthesis?
I want to remove all the text within a parenthesis, along with the parentheses, to return only the text that is outside them, as follows: texto = 'bla bla bla (ble ble)' I want you to turn: texto =…
-
0
votes2
answers1557
viewsMaking a date set Random with pandas
I’m trying to extract 15O lines from a 500-line dataset. So I’d like to do it on Andom. My data objeto,cor,label cachorro,branco,animal manga,laranja,fruta calça,preta,roupa My script import pandas…
-
0
votes1
answer211
viewsTranspose columns to rows in Python data frame
Good evening Stack colleagues. First I want to thank you for the help that this vcs provide. I come please ask for more help. According to the image below, I would like to transpose all data…
-
0
votes2
answers778
viewsPython pandas: Drop rows with duplicate column and another column with null value
I would like to drop in lines where the column 1 is duplicated and column 2 is null. I expect an output that way Col1 Col2 A 123 A NaN B NaN B 456 Exit Col1 Col2 A 123 B 456 I tried to do more or…
-
0
votes1
answer632
viewsPandas: Convert Dataframes to Image
Given a Dataframe as the following: df = pd.DataFrame({'id_emp' : [13524791000109, 12053850000137, 4707821000113, 4707821000114, 1], 'name_emp': ['Cristiano', 'Gaúcho', 'Fenômeno','Angelin',…
-
0
votes1
answer1123
viewsHow to get only the records not duplicated with pandas
How would you get only the un-duplicated lines of a dataframe? Without them being single records, so df.unique() would not fit here. Only the ones that exist 1 same. I tried that way, but I don’t…
-
0
votes1
answer1113
viewsMerging two columns into a new column named 'Class' (dataframe Pandas)
df_downsampled[df_downsampled['attack_cat']=="DoS"] Take all the dataframe 'df_downsampled' where the column 'attack_cat' has the value Dos. Dataset:…
-
0
votes1
answer57
viewsSelect values from one column from other columns
I am trying to select only column values flightID where Depdelay and Arrdelay are larger than 15. I tried that: delay = data.loc[(data['ArrDelay'] > 15) & (data['DepDelay'] > 15),…
-
0
votes1
answer1593
viewsConvert column to string where have pandas null values
How do I convert a column to string every time I try to do `df['COL1'] = ['COL1'].astype(str)` where there are nulls, pandas convert to string "NAN", have some way around this problem?…
-
0
votes1
answer100
viewsParse file . txt using Pandas from external rules in a JSON
I have a data set in . txt format that has its own formatting with the rules described by a separate JSON file. Is there any direct way to tell Pandas to use this JSON as the basis to decode . txt?…
-
0
votes1
answer517
viewsPandas dataframe.Loc() does not find the record
Good morning! I am trying to manipulate a Dataframe that originates in a DRE report (accounting). I would like the index to be the account code, which I have already been able to do. However,…
-
0
votes1
answer31
viewsProblems using iloc pandas
I want to create a new DataFrame with the following condition: marvel.loc[ marvel['Orientation'] != 'NaN' ] I mean, I want every line that has the column 'Orientation'== 'NaN' are deleted, but there…
-
0
votes1
answer978
views -
0
votes1
answer401
viewsPython mining (prediction using csv)
I am now starting programming in Python language and I am studying data mining with artificial neural network. What should I do to make predictions from a . csv file? Then how to save the results in…
-
0
votes1
answer34
viewsPython - Problem with df.apply(Function)
beauty? Can I get a little help? Just call. I have a dataframe with some string information and wanted to change them to text. To simplify, imagine that the table contains information of the…
-
0
votes1
answer926
viewsSelect higher value per row of two columns (Python)
I have a dataframe with several columns, the last two are where I sum and multiply the other columns, at the end I create a column that should select the highest value between these two columns, for…
-
0
votes1
answer191
viewsExport from pandas to MS SQL using to_sql and sqlalchemy
My problem is with Float values example: df = pd.DataFrame([1.45]) conn_str = 'mssql+pyodbc:///?odbc_connect={}'.format(params) engine = create_engine(conn_str) df.to_sql(name='teste',con=engine,…
-
0
votes1
answer1716
viewsSearch all different elements of a column (pandas)
I developed this part with the functions learned in the classroom #importando pandas import pandas as pd #criando o dataframe base = pd.read_csv('C:\\Users\\lsilv\\Desktop\\acessos.csv') #renomeei…
-
0
votes1
answer58
viewsReplace words in a text that must be formed of letters and numbers
I am trying to replace words in a text that are formed, obligatorily, formed of letters and numbers. I tried that: def passwords(): df['C'] = df['C'].str.replace(r'[a-zA-Z0-9]', '<password>')…
-
0
votes1
answer45
viewsTransform Pandas str objects into numeric values
How do I use Python to transform the following string: [[98 9] [55 16] [9 50] [68 0] [24 1] [80 16]] in two numerical vector chains (the first string containing the first values: 98 55 9 ... and the…
-
0
votes1
answer60
viewsXOR operation by filtering my list values in Dataframe columns
I have several lists and a single dataframe, my goal is to filter my columns that contain the same values from my list and create a dynamic XOR operation. When you find my XOR result equal to 0, the…
-
0
votes1
answer74
viewsI cannot extract data from a specific column
My Dataframe has several columns and one of them is not being read when I try to use indexing (e.g., bar_0617 = media_0617['Bar']). The following error appears: Keyerror: 'Bar'. I do not know what…
-
0
votes1
answer84
viewsWarning pandas, 2 loopings!
Guys I’m having trouble with this looping, because it’s a situation that I can’t solve with np.where, why does the DataFrame to find the value of the gain or loss from another condition, which comes…
-
0
votes1
answer76
viewsIs there any way to replace one number with another in a Dataframe?
I have a dataset to analyze, and it in some columns contains values that reference others. I would like to know if there is any way to replace one numerical value with another. I tried to do this…
pandasasked 4 years, 11 months ago Luis Amaro 105 -
0
votes1
answer25
viewsTrying to lambda the dataset?
I’m trying to apply this function to the dataset: number_outliers = (df2 < (Q1 - 1.5 * IQR)) | (df2 > (Q3 + 1.5 * IQR)) df2.apply(((lambda x:df2[~((df2 < (Q1 - 1.5 * IQR)) | (df2 > (Q3 +…
-
0
votes1
answer139
viewsHow to read a JSON with missing fields to fill in a dictionary?
In Python 3 this code reads the Federal Senate API, the proposition data: import requests import pandas as pd headers = {"Accept" : "application/json"} url =…
-
0
votes2
answers239
viewsSelect only a part of the Dataframe title
Imagine the following situation, I have a Dataframe with any name. Within this Dataframe I have columns with the following titles More(abc), Less(abc), Sub(abc), following the data of each column.…
-
0
votes1
answer5443
viewsConvert str(Object) to int (python)
I have a dataset with two columns and would like to create a third column called Ranking that will receive values based on the Brand column. So Mark A will receive the value 10 and so on. df =…
-
0
votes2
answers374
viewsBreaking string from a character
Inside my dataframe, one of the columns has information separated by comma, I would like to delete everything within the string after the first comma. Follow the code I’m trying to use: df_movies =…
-
0
votes2
answers665
viewsLoad multiple concatenated CSV at once in Python
Talk personal, quiet? There is an easier way to load . csv concatenated at once instead of doing the procedure below? z1 = pd.read_csv('arquivo1.csv') z2 = pd.read_csv('arquivo2.csv') z3 =…
-
0
votes1
answer628
viewsAll data from a row in the dataframe is going to the first column using python pandas
I’m reading a CSV file with pandas on a dataframe, it turns out on line 10, all the data is going to the first column, this way: How can I solve this problem and separate correctly? I need only the…
-
0
votes1
answer1460
viewsImport txt files with pandas
I’m starting in the area of machine Learning, following a website that suggested the following initial model: import pandas as pd from sklearn import linear_model import matplotlib.pyplot as plt…
-
0
votes1
answer2111
viewsHow to convert values into percentage of a "total" column into pandas?
Hello! I’m learning about Python and Numpy, but I’m having trouble working with percentages. Considering that the total column corresponds to 100%, as I do to obtain the respective percentages of…
-
0
votes1
answer1219
viewsPython Pandas insert records into a column according to the data present in a Dataframe
Good evening, I have an Excel spreadsheet that has a column called Cod and within that column are the valores: 01, 02, 03 I need to create another column in this table that does the following:…
-
0
votes1
answer265
viewsUsing groupby in a dataframe
I have a dataframe with 60 columns, but for the case need only 3 ID DT_DATE NR_PRICE 0 22828949 2019-02-26 453.00 1 22828949 2019-02-22 453.00 2 22828949 2019-02-18 453.00 3 22828949 2019-02-05…
-
0
votes0
answers1022
viewsHow to change bar colors individually in matplotlib?
Hello! Can anyone explain to me how the principle works to change the colors of the bars individually? All I can do is change the color of the whole chart. For example: From Blue to Black / From…
-
0
votes1
answer1186
viewsHow can I remove the first column of pandas numbers
Can anyone tell me how I can remove the first column of output of pandas and pepper column? Image of what I want to remove: My CSV: Link:…
-
0
votes1
answer624
viewsPerform date filtering within a column using Python
good afternoon. I need to do an Excel file filtering, this filtering consists of taking a particular column and performing its filter. I’m a beginner here and I don’t know if I’m making the most…
-
0
votes1
answer361
viewsPython error locale
locale.setlocale(locale.LC_ALL, "Portuguese_Brazil.1252") data = pd.read_excel('C:/Users/t714591/Videos/bancos/base.xlsx') data["Valor"] = locale.currency(data["Valor"], grouping=True, symbol=None)…