dataframe

iterrows cannot iterate over DataFrame Eror: touple object has no attribute “A”

荒凉一梦 提交于 2021-02-05 11:13:50
问题 When I try to iterate over a dataframe, somehow dtype is changed. dates = pd.date_range('20130101',periods=6) df = pd.DataFrame(np.random.randn(6,4),index=dates,columns=list('ABCD')) df A B C D 2013-01-01 -1.328046 -0.545127 -0.033153 1.190336 2013-01-02 -0.549147 0.447161 1.179931 0.397521 2013-01-03 -0.106707 -0.327574 -0.933817 -1.032949 2013-01-04 -0.519988 -1.007374 -0.794482 -1.757222 2013-01-05 -0.739735 1.220599 -1.387994 -0.116178 2013-01-06 0.262876 -0.679471 -0.568768 -0.277880 now

Filter function dplyr seems to be not working [closed]

拈花ヽ惹草 提交于 2021-02-05 11:12:49
问题 Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . Improve this question Let's presume I have a data.fram called exprCore1 loaded in R-Studio, the df looks like this: measure qid value 1 p5 1 0.2 2 p100 1 0.8 3 map 1 0.22 4 p5 2 0.4 5 p100 2 0.5 6 map 2 0.32 Basically all want is every column in which the measurement method is "map"

Trying to find row associated with max value in dataframe R

我的梦境 提交于 2021-02-05 11:09:47
问题 Like the title says. I am having trouble. for example I have a 2 column (V1,V2) dataframe with lots of rows, around 300,000. I know that max(df$V2) will give me the max value of that second column. Now that I know my max value, how can I get the entire row associated with that value. Thanks! 回答1: You have to write df[which.max(df$V2), ] If more than one row contains the max: i <- max(df$V2) df[which(df$V2 == i), ] 来源: https://stackoverflow.com/questions/36802736/trying-to-find-row-associated

add horizontal limit line to time series plot in python

对着背影说爱祢 提交于 2021-02-05 10:50:13
问题 I want to add horizontal upper and lower limit line for Temparature timeseries plot. Lets say upper limit line at 30 and lower limit line at 10. df3.plot(x="Date", y=["Temp.PM", "Temp.AM"],figsize=(20,8)) 回答1: I think this solution can help you import matplotlib.pyplot as plt %matplotlib inline df3.plot(x="Date", y=["Temp.PM", "Temp.AM"],figsize=(20,8)) plt.axhline(30) plt.axhline(10) 回答2: plt.plot(df3['Date'], df3[["Temp.PM", "Temp.AM"]]) plt.axhline(30, color='r') plt.axhline(10, color='b')

How can I remove emojis from a dataframe?

隐身守侯 提交于 2021-02-05 10:48:06
问题 I know that test = [] for item in my_texts: test.append(item.encode('ascii', 'ignore').decode('ascii')) removes emojis from a list. But how can I remove emojis from a dataframe? When I try a = [] for item in goldtest['Text']: a.append(item.encode('ascii', 'ignore').decode('ascii')) I get only the last entry of goldtest. When I try the code on the whole dataframe, I get ''AttributeError: 'DataFrame' object has no attribute 'encode''' 回答1: This would be the equivalent code for pandas. It

R: Sorting all columns in data frame by an alphanumeric column

倾然丶 夕夏残阳落幕 提交于 2021-02-05 10:37:15
问题 I want to sort all columns of a data frame in R by a column containing alphanumeric data. Here is an example data frame: R> dd <- data.frame(b = c("Hi", "Med", "Hi", "Low"), x = c("A", "D", "A", "C"), y = c(8, 3, 9, 9), z = c("A1", "A3", "A10", "A2")) 1 Hi A 8 A1 2 Med D 3 A3 3 Hi A 9 A10 4 Low C 9 A2 I would like to sort the entire data frame on column z. The desired output looks like this - with the info across columns staying consistent: 1 Hi A 8 A1 2 Low C 9 A2 3 Med D 3 A3 4 Hi A 9 A10

How to remove NA from data frames of a list?

你离开我真会死。 提交于 2021-02-05 09:42:39
问题 I have a list of my.list that looks like this $S1 A B C D 1 101027 NA 0.48 NA 2 101031 1.50 1.30 0.8666667 3 101032 1.40 0.78 0.5571429 4 101127 NA NA NA 5 101220 9.30 7.30 0.7849462 $S2 A B C D 1 102142 NA 0.45 NA 2 102143 0.70 1.20 1.7142857 3 102144 NA 0.44 NA 4 102148 0.45 NA NA 5 102151 0.91 0.64 0.7032967 6 102152 0.78 NA NA I would like to remove any rows that have NA from the data frame of the list so it looks like $S1 A B C D 2 101031 1.50 1.30 0.8666667 3 101032 1.40 0.78 0.5571429

Iteration through rows of a dataframe within group of columns in R

天涯浪子 提交于 2021-02-05 09:31:09
问题 I have a dataframe df with 6 fields A,B,C,D,E & F. My requirement is to create a new column G which is equal to the previous value(C) + previous value(D) + previous (G) - F. But this needs to be implemented at a group level through columns A & B (group by A & B). In case it is the first row within the group then the value in column G should be equal to E. Sample Df - A B C D E F 1 2 100 200 300 0 1 2 110 210 310 10 1 2 120 130 300 10 1 1 140 150 80 0 1 1 50 60 80 20 1 1 50 60 80 20 Output - A

Pandas convert float to int if decimals are 0

两盒软妹~` 提交于 2021-02-05 08:56:11
问题 I have a pandas dataframe, in which some columns have numeric values while others don't, as shown below: City a b c Detroit 129 0.54 2,118.00 East 188 0.79 4,624.4712 Houston 154 0.65 3,492.1422 Los Angeles 266 1.00 7,426.00 Miami 26 0.11 792.18 MidWest 56 0.24 772.7813 I want to round off these numeric values to 2 decimal places, for which I am using: df = df.replace(np.nan, '', regex=True) After which df becomes: City a b c Detroit 129.0 0.54 2,118.0 East 188.0 0.79 4,624.47 Houston 154.0 0

Pandas convert float to int if decimals are 0

馋奶兔 提交于 2021-02-05 08:56:09
问题 I have a pandas dataframe, in which some columns have numeric values while others don't, as shown below: City a b c Detroit 129 0.54 2,118.00 East 188 0.79 4,624.4712 Houston 154 0.65 3,492.1422 Los Angeles 266 1.00 7,426.00 Miami 26 0.11 792.18 MidWest 56 0.24 772.7813 I want to round off these numeric values to 2 decimal places, for which I am using: df = df.replace(np.nan, '', regex=True) After which df becomes: City a b c Detroit 129.0 0.54 2,118.0 East 188.0 0.79 4,624.47 Houston 154.0 0