Linked Questions
26 questions linked to/from Creating a Pandas DataFrame from a Numpy array: How do I specify the index column and column headers?
3
votes
4
answers
19k
views
convert numpy array into dataframe [duplicate]
I have a numpy array and I want to convert it into a dataframe.
import numpy as np
import pandas as pd
nparray = np.array([[1,2,3,4,5],[6,7,8,9,10]])
How do I convert it into a dataframe where ...
0
votes
0
answers
247
views
Creating Dataframe with numpy array with index and columns [duplicate]
I have a numpy array with the following shape:
numpy_x.shape
(9982, 26)
I want turn this numpy to dataframe:
x_new_df = pd.DataFrame(numpy_x)
And my new dataframe is:
x_new_df
How to can I generate ...
0
votes
0
answers
48
views
How to split all objects within an array into 2 columns? [duplicate]
Let say I have an array:
array([('a', 1), ('b', 2), ('c', 3), ...,
('x', 24), ('y', 25), ('z', 26)],
dtype=object)
How do I split it into 2 columns as in 'alphabet' and 'order'? Much ...
17
votes
1
answer
56k
views
Creating a Pandas DataFrame with a numpy array containing multiple types
I want to create a pandas dataframe with default values of zero, but one column of integers and the other of floats. I am able to create a numpy array with the correct types, see the values variable ...
13
votes
4
answers
39k
views
How to set the value of a pandas column as list
I want to set the value of a pandas column as a list of strings. However, my efforts to do so didn't succeed because pandas take the column value as an iterable and I get a: ValueError: Must have ...
8
votes
3
answers
27k
views
Building a DataFrame with column names in Python
In trying to get familiar with DataFrame in Python I got stuck in the following step...
I try to create a dataframe from an array:
from numpy import *
import pandas as pd
dat = array([[0....
-1
votes
2
answers
5k
views
Convert a numpy array to a DataFrame in pyspark to export as csv
I have a numpy array in pyspark and I would like to convert this to a DataFrame so I can write it out as a csv to view it.
I read the data in initially from a DataFrame however I had to convert to an ...
1
vote
2
answers
3k
views
How can I convert an array of class objects to a dataframe with columns in Pandas?
With the following class:
class Test:
a : str
b : str
and the following data frame:
output = pd.DataFrame(columns=['a', 'b']
how can I convert an array, or list, of class Test into a pandas ...
3
votes
2
answers
11k
views
Is there a way to convert npz files to panda dataframe?
I have a large npz file that l've loaded with numpy's np.load. I want to convert this to panda's dataframe so l can apply machine learning algorithms (KNN, K-Means, DT) using scikit-learn. I am new to ...
0
votes
3
answers
1k
views
How to combine a list of lists into a dictionary where the first sublist is mapped to corresponding values in all subsequent sublists?
I have a list of lists, where the first list is a 'header' list and the rest are data lists. Each of these 'sub' lists are the same size, as shown below:
list1 = [
["Sno", "Name&...
0
votes
3
answers
6k
views
Append a column to a dataframe in Pandas
I am trying to append a numpy.darray to a dataframe with little success.
The dataframe is called user2 and the numpy.darray is called CallTime.
I tried:
user2["CallTime"] = CallTime.values
but I get ...
1
vote
1
answer
4k
views
'numpy.ndarray' object has no attribute 'iterrows' while predicting value using lstm in python
I have a dataset with three inputs and trying to predict next value of X1 with the combination of previous inputs values.
My three inputs are X1, X2, X3, X4.
So here I am trying to predict next ...
0
votes
1
answer
3k
views
Pandas groupby for k-fold cross-validation with aggregation
say I have a data frame,df, with columns: id |site| time| clicks |impressions
I want to use the machine learning technique of k-fold cross validation ( split the data randomly into k=10 equal sized ...
1
vote
2
answers
703
views
How to write a numpy ndarray to a textfile?
Say that I got this ndarray using numpy that I want to write to a text file. :
[[1 2 3 4]
[5 6 7 8]
[9 10 11 12]]
This is my code:
width, height = matrix.shape
with open('file....
1
vote
2
answers
908
views
Pandas DataFrame from Numpy Array - column order
I'm trying to read data from a .csv file using Pandas, smoothing it with Savitsky-Golay filter, filtering it and then using Pandas again to write an output csv file. Data must be converted from ...