how to check all values in particular column has same data type or not?Counting indexes in pandasPandas Query Optimization On Multiple ColumnsOutlier detection by unsupervised algorithm: Fraud DetectionMerge information of rows with same dateTraining on data with inherently non-applicable data cellsHow to print x-axes labels in pandas.Series.plot()?Processing csv file with more than 700K rows of dataUnderstanding missing values in datasetChange values of a particular column to value_count()Data sets that have strings and numerical data all in one column
Is American Sign Language phonetic?
Conveying the idea of "down the road" (i.e. in the future)
Does every Ubuntu question answer apply to it's derivatives? (Xubuntu, Lubuntu, Kubuntu)
Why is my vegetable stock bitter, but the chicken stock not?
Redirect output on-the-fly - looks not possible in Linux, why?
Can an animal produce milk all the time?
What benefits are there to blocking most search engines?
Can I voluntarily exit from the US after a 20 year overstay, or could I be detained at the airport?
How is the speed of nucleons in the nucleus measured?
How to print variable value in next line using echo command
Today I am 20 but next year I will turn 22
Has Boris Johnson ever referred to any of his opponents as "traitors"?
SHA3-255, one bit less
As an interviewer, how to conduct interviews with candidates you already know will be rejected?
Should I hang doors before or after drywall?
Can we calculate the orbit of exoplanets?
What is the origin of the minced oath “Jiminy”?
Does python reuse repeated calculation results?
What's the correct way to determine turn order in this situation?
Does the DOJ's declining to investigate the Trump-Zelensky call ruin the basis for impeachment?
Could the Queen overturn the UK Supreme Court ruling regarding prorogation of Parliament?
How fast are we moving relative to the CMB?
Can I pay off my mortgage with a new one?
In 1700s, why was 'books that never read' grammatical?
how to check all values in particular column has same data type or not?
Counting indexes in pandasPandas Query Optimization On Multiple ColumnsOutlier detection by unsupervised algorithm: Fraud DetectionMerge information of rows with same dateTraining on data with inherently non-applicable data cellsHow to print x-axes labels in pandas.Series.plot()?Processing csv file with more than 700K rows of dataUnderstanding missing values in datasetChange values of a particular column to value_count()Data sets that have strings and numerical data all in one column
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
$begingroup$
I have column 'ABC' which has 5000 rows. Currently, dtype of column is object. Mostly it has string values but some values dtype is not string, I want to find all those rows and modify those rows. Column is as following:
1 abc
2 def
3 ghi
4 23
5 mno
6 null
7 qwe
8 12-11-2019
...
...
...
4900 ert
5000 tyu
In above case, I can use for loop to find out rows which do not have desired dtype. I just wanted to know, is their better way to solve this issue.
Note: I am using Pandas.
python pandas data-cleaning numpy
New contributor
Kiran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
add a comment
|
$begingroup$
I have column 'ABC' which has 5000 rows. Currently, dtype of column is object. Mostly it has string values but some values dtype is not string, I want to find all those rows and modify those rows. Column is as following:
1 abc
2 def
3 ghi
4 23
5 mno
6 null
7 qwe
8 12-11-2019
...
...
...
4900 ert
5000 tyu
In above case, I can use for loop to find out rows which do not have desired dtype. I just wanted to know, is their better way to solve this issue.
Note: I am using Pandas.
python pandas data-cleaning numpy
New contributor
Kiran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
$begingroup$
In pandas dtypes can be inferred by trying to cast them and making un-castable ones to string dtypes as inobject, which means all elements in a single column will be in a same datatype. You cant have two diff. row elements in the same column to be of different datatypes.
$endgroup$
– Kiritee Gak
7 hours ago
$begingroup$
@KiriteeGak: I think that is not quite true. You can test that yourself. Create a dataframe, with at least two rows indexed 1 and 2. Then dodf.loc[1, 'new_column']= 'my_value'. Then dodf['new_column'].map(type). You will see, that all but the first row containfloats. That is because the other rows containNaN, which is afloatand not astr. Likewise you could mix in other object types in yourobjectcolumn if you like (but it is probably not a very good idea).
$endgroup$
– jottbe
7 hours ago
$begingroup$
I stand corrected. Thanks :)
$endgroup$
– Kiritee Gak
6 hours ago
add a comment
|
$begingroup$
I have column 'ABC' which has 5000 rows. Currently, dtype of column is object. Mostly it has string values but some values dtype is not string, I want to find all those rows and modify those rows. Column is as following:
1 abc
2 def
3 ghi
4 23
5 mno
6 null
7 qwe
8 12-11-2019
...
...
...
4900 ert
5000 tyu
In above case, I can use for loop to find out rows which do not have desired dtype. I just wanted to know, is their better way to solve this issue.
Note: I am using Pandas.
python pandas data-cleaning numpy
New contributor
Kiran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
I have column 'ABC' which has 5000 rows. Currently, dtype of column is object. Mostly it has string values but some values dtype is not string, I want to find all those rows and modify those rows. Column is as following:
1 abc
2 def
3 ghi
4 23
5 mno
6 null
7 qwe
8 12-11-2019
...
...
...
4900 ert
5000 tyu
In above case, I can use for loop to find out rows which do not have desired dtype. I just wanted to know, is their better way to solve this issue.
Note: I am using Pandas.
python pandas data-cleaning numpy
python pandas data-cleaning numpy
New contributor
Kiran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Kiran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Kiran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 8 hours ago
KiranKiran
1084 bronze badges
1084 bronze badges
New contributor
Kiran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Kiran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$begingroup$
In pandas dtypes can be inferred by trying to cast them and making un-castable ones to string dtypes as inobject, which means all elements in a single column will be in a same datatype. You cant have two diff. row elements in the same column to be of different datatypes.
$endgroup$
– Kiritee Gak
7 hours ago
$begingroup$
@KiriteeGak: I think that is not quite true. You can test that yourself. Create a dataframe, with at least two rows indexed 1 and 2. Then dodf.loc[1, 'new_column']= 'my_value'. Then dodf['new_column'].map(type). You will see, that all but the first row containfloats. That is because the other rows containNaN, which is afloatand not astr. Likewise you could mix in other object types in yourobjectcolumn if you like (but it is probably not a very good idea).
$endgroup$
– jottbe
7 hours ago
$begingroup$
I stand corrected. Thanks :)
$endgroup$
– Kiritee Gak
6 hours ago
add a comment
|
$begingroup$
In pandas dtypes can be inferred by trying to cast them and making un-castable ones to string dtypes as inobject, which means all elements in a single column will be in a same datatype. You cant have two diff. row elements in the same column to be of different datatypes.
$endgroup$
– Kiritee Gak
7 hours ago
$begingroup$
@KiriteeGak: I think that is not quite true. You can test that yourself. Create a dataframe, with at least two rows indexed 1 and 2. Then dodf.loc[1, 'new_column']= 'my_value'. Then dodf['new_column'].map(type). You will see, that all but the first row containfloats. That is because the other rows containNaN, which is afloatand not astr. Likewise you could mix in other object types in yourobjectcolumn if you like (but it is probably not a very good idea).
$endgroup$
– jottbe
7 hours ago
$begingroup$
I stand corrected. Thanks :)
$endgroup$
– Kiritee Gak
6 hours ago
$begingroup$
In pandas dtypes can be inferred by trying to cast them and making un-castable ones to string dtypes as in
object, which means all elements in a single column will be in a same datatype. You cant have two diff. row elements in the same column to be of different datatypes.$endgroup$
– Kiritee Gak
7 hours ago
$begingroup$
In pandas dtypes can be inferred by trying to cast them and making un-castable ones to string dtypes as in
object, which means all elements in a single column will be in a same datatype. You cant have two diff. row elements in the same column to be of different datatypes.$endgroup$
– Kiritee Gak
7 hours ago
$begingroup$
@KiriteeGak: I think that is not quite true. You can test that yourself. Create a dataframe, with at least two rows indexed 1 and 2. Then do
df.loc[1, 'new_column']= 'my_value'. Then do df['new_column'].map(type). You will see, that all but the first row contain floats. That is because the other rows contain NaN, which is a float and not a str. Likewise you could mix in other object types in your object column if you like (but it is probably not a very good idea).$endgroup$
– jottbe
7 hours ago
$begingroup$
@KiriteeGak: I think that is not quite true. You can test that yourself. Create a dataframe, with at least two rows indexed 1 and 2. Then do
df.loc[1, 'new_column']= 'my_value'. Then do df['new_column'].map(type). You will see, that all but the first row contain floats. That is because the other rows contain NaN, which is a float and not a str. Likewise you could mix in other object types in your object column if you like (but it is probably not a very good idea).$endgroup$
– jottbe
7 hours ago
$begingroup$
I stand corrected. Thanks :)
$endgroup$
– Kiritee Gak
6 hours ago
$begingroup$
I stand corrected. Thanks :)
$endgroup$
– Kiritee Gak
6 hours ago
add a comment
|
1 Answer
1
active
oldest
votes
$begingroup$
You can get the type of the entries of your column with map:
df['ABC'].map(type)
So to filter on all values, which are not stored as str, you can use:
df['ABC'].map(type) != str
If however you just want to check if some of the rows contain a string, that has a special format (like a date), you can check this with a regex like:
df['ABC'].str.match('[0-9]4-[0-9]2-[0-9]2')
But of course, that is no exact date check. E.g. it would also return True for values like 0000-13-91, but this was only meant to give you an idea anyways.
$endgroup$
$begingroup$
thanks, it helped..
$endgroup$
– Kiran
7 hours ago
add a comment
|
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "557"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Kiran is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f60955%2fhow-to-check-all-values-in-particular-column-has-same-data-type-or-not%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
You can get the type of the entries of your column with map:
df['ABC'].map(type)
So to filter on all values, which are not stored as str, you can use:
df['ABC'].map(type) != str
If however you just want to check if some of the rows contain a string, that has a special format (like a date), you can check this with a regex like:
df['ABC'].str.match('[0-9]4-[0-9]2-[0-9]2')
But of course, that is no exact date check. E.g. it would also return True for values like 0000-13-91, but this was only meant to give you an idea anyways.
$endgroup$
$begingroup$
thanks, it helped..
$endgroup$
– Kiran
7 hours ago
add a comment
|
$begingroup$
You can get the type of the entries of your column with map:
df['ABC'].map(type)
So to filter on all values, which are not stored as str, you can use:
df['ABC'].map(type) != str
If however you just want to check if some of the rows contain a string, that has a special format (like a date), you can check this with a regex like:
df['ABC'].str.match('[0-9]4-[0-9]2-[0-9]2')
But of course, that is no exact date check. E.g. it would also return True for values like 0000-13-91, but this was only meant to give you an idea anyways.
$endgroup$
$begingroup$
thanks, it helped..
$endgroup$
– Kiran
7 hours ago
add a comment
|
$begingroup$
You can get the type of the entries of your column with map:
df['ABC'].map(type)
So to filter on all values, which are not stored as str, you can use:
df['ABC'].map(type) != str
If however you just want to check if some of the rows contain a string, that has a special format (like a date), you can check this with a regex like:
df['ABC'].str.match('[0-9]4-[0-9]2-[0-9]2')
But of course, that is no exact date check. E.g. it would also return True for values like 0000-13-91, but this was only meant to give you an idea anyways.
$endgroup$
You can get the type of the entries of your column with map:
df['ABC'].map(type)
So to filter on all values, which are not stored as str, you can use:
df['ABC'].map(type) != str
If however you just want to check if some of the rows contain a string, that has a special format (like a date), you can check this with a regex like:
df['ABC'].str.match('[0-9]4-[0-9]2-[0-9]2')
But of course, that is no exact date check. E.g. it would also return True for values like 0000-13-91, but this was only meant to give you an idea anyways.
edited 7 hours ago
answered 7 hours ago
jottbejottbe
18210 bronze badges
18210 bronze badges
$begingroup$
thanks, it helped..
$endgroup$
– Kiran
7 hours ago
add a comment
|
$begingroup$
thanks, it helped..
$endgroup$
– Kiran
7 hours ago
$begingroup$
thanks, it helped..
$endgroup$
– Kiran
7 hours ago
$begingroup$
thanks, it helped..
$endgroup$
– Kiran
7 hours ago
add a comment
|
Kiran is a new contributor. Be nice, and check out our Code of Conduct.
Kiran is a new contributor. Be nice, and check out our Code of Conduct.
Kiran is a new contributor. Be nice, and check out our Code of Conduct.
Kiran is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Data Science Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f60955%2fhow-to-check-all-values-in-particular-column-has-same-data-type-or-not%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
In pandas dtypes can be inferred by trying to cast them and making un-castable ones to string dtypes as in
object, which means all elements in a single column will be in a same datatype. You cant have two diff. row elements in the same column to be of different datatypes.$endgroup$
– Kiritee Gak
7 hours ago
$begingroup$
@KiriteeGak: I think that is not quite true. You can test that yourself. Create a dataframe, with at least two rows indexed 1 and 2. Then do
df.loc[1, 'new_column']= 'my_value'. Then dodf['new_column'].map(type). You will see, that all but the first row containfloats. That is because the other rows containNaN, which is afloatand not astr. Likewise you could mix in other object types in yourobjectcolumn if you like (but it is probably not a very good idea).$endgroup$
– jottbe
7 hours ago
$begingroup$
I stand corrected. Thanks :)
$endgroup$
– Kiritee Gak
6 hours ago