tagged [dataframe]

Delete a column from a Pandas DataFrame

Delete a column from a Pandas DataFrame To delete a column in a DataFrame, I can successfully use: But why can't I use the following? Since it is possible to access the Series via `df.column_name`, I ...

6 Feb at 03:5

How to create a dictionary of two pandas DataFrame columns

How to create a dictionary of two pandas DataFrame columns What is the most efficient way to organise the following pandas Dataframe: data = into a dictionary like `alphabet[1 : 'a', 2 : 'b', 3 : 'c',...

4 Dec at 19:54

Combine two columns of text in pandas dataframe

Combine two columns of text in pandas dataframe I have a 20 x 4000 dataframe in Python using pandas. Two of these columns are named `Year` and `quarter`. I'd like to create a variable called `period` ...

13 Aug at 23:27

Convert Pandas Column to DateTime

Convert Pandas Column to DateTime I have one field in a pandas DataFrame that was imported as string format. It should be a datetime variable. How do I convert it to a datetime column and then filter ...

29 Jan at 18:42

Convert data.frame column format from character to factor

Convert data.frame column format from character to factor I would like to change the format (class) of some columns of my data.frame object (`mydf`) from to . I don't want to do this when I'm reading ...

6 Dec at 08:37

Creating a zero-filled pandas data frame

Creating a zero-filled pandas data frame What is the best way to create a zero-filled pandas data frame of a given size? I have used: Is there a better way to do it?

24 Feb at 16:4

How do I create test and train samples from one dataframe with pandas?

How do I create test and train samples from one dataframe with pandas? I have a fairly large dataset in the form of a dataframe and I was wondering how I would be able to split the dataframe into two ...

10 Jun at 17:24

What is dtype('O'), in pandas?

What is dtype('O'), in pandas? I have a dataframe in pandas and I'm trying to figure out what the types of its values are. I am unsure what the type is of column `'Test'`. However, when I run `myFrame...

8 Jun at 23:47

Get the name of a pandas DataFrame

Get the name of a pandas DataFrame How do I get the name of a DataFrame and print it as a string? Example: `boston` (var name assigned to a csv file)

16 Dec at 10:29

Writing a pandas DataFrame to CSV file

Writing a pandas DataFrame to CSV file I have a dataframe in pandas which I would like to write to a CSV file. I am doing this using: And getting the following error: - -

19 Dec at 08:51

Spark: subtract two DataFrames

Spark: subtract two DataFrames In Spark version one could use `subtract` with 2 `SchemRDD`s to end up with only the different content from the first one `onlyNewData` contains the rows in `todaySchemR...

6 Oct at 09:52

Python Pandas: How to read only first n rows of CSV files in?

Python Pandas: How to read only first n rows of CSV files in? I have a very large data set and I can't afford to read the entire data set in. So, I'm thinking of reading only one chunk of it to train ...

14 Feb at 01:51

Select first 4 rows of a data.frame in R

Select first 4 rows of a data.frame in R How can I select the first 4 rows of a `data.frame`:

19 Jan at 01:29

How to replace text in a string column of a Pandas dataframe?

How to replace text in a string column of a Pandas dataframe? I have a column in my dataframe like this: and I want to replace the `,` comma with `-` dash. I'm currently using this method but nothing ...

21 Dec at 22:11

How to loop through each row of dataFrame in pyspark

How to loop through each row of dataFrame in pyspark E.g The above statement prints theentire table on terminal. But I want to access each row in that table using `for` or `while` to perform further c...

Get current number of partitions of a DataFrame

Get current number of partitions of a DataFrame Is there any way to get the current number of partitions of a DataFrame? I checked the DataFrame javadoc (spark 1.6) and didn't found a method for that,...

Convert float64 column to int64 in Pandas

Convert float64 column to int64 in Pandas I tried to convert a column from data type `float64` to `int64` using: but got an error: > NameError: name 'int64' is not defined The column has number of peo...

13 May at 18:23

Filtering Pandas DataFrames on dates

Filtering Pandas DataFrames on dates I have a Pandas DataFrame with a 'date' column. Now I need to filter out all rows in the DataFrame that have dates outside of the next two months. Essentially, I o...

List all column except for one in R

List all column except for one in R > [Drop Columns R Data frame](https://stackoverflow.com/questions/4605206/drop-columns-r-data-frame) Let's say I have a dataframe with column c1, c2, c3. I want t...

23 May at 12:10

Pandas read_csv: low_memory and dtype options

Pandas read_csv: low_memory and dtype options ...gives an error: > .../site-packages/pandas/io/parsers.py:1130: DtypeWarning: Columns (4,5,7,16) have mixed types. Specify dtype option on import or set...

20 Jun at 01:52

Pandas Replace NaN with blank/empty string

Pandas Replace NaN with blank/empty string I have a Pandas Dataframe as shown below: I want to remove the NaN values with an empty string so that it looks like so:

20 Oct at 20:38

Renaming column names of a DataFrame in Spark Scala

Renaming column names of a DataFrame in Spark Scala I am trying to convert all the headers / column names of a `DataFrame` in Spark-Scala. as of now I come up with following code which only replaces a...

Check whether values in one data frame column exist in a second data frame

Check whether values in one data frame column exist in a second data frame I have two data frames (A and B), both with a column 'C'. I want to check if values in column 'C' in data frame A exists in d...

15 Jul at 20:33

Find maximum value of a column and return the corresponding row values using Pandas

Find maximum value of a column and return the corresponding row values using Pandas ![Structure of data;](https://i.stack.imgur.com/a34it.png) Using Python Pandas I am trying to find the `Country` & `...

14 Jan at 08:52

Move a column to first position in a data frame

Move a column to first position in a data frame I would like to have the last column of the data frame moved to the start (as first column). How can I do it in R? My data.frame has about a thousand co...

31 Dec at 09:54